0

I am a beginner in Entity framework and I want to insert operation through Linq To entity.

My code:

databaseentity entity = new databaseentity();
car c = new car { name = TextBox1.Text };

But when I write Addobject in code it shows error and this method is not supported by Ef:

entity.cars.AddObject(c);

How can I resolve this problem? I have already added system.data.objects namespace.

Mansfield
  • 14,445
  • 18
  • 76
  • 112
user2516261
  • 73
  • 1
  • 8

1 Answers1

1

Try using

entity.AddToCars(c);
entity.SaveChanges();
Loetn
  • 3,832
  • 25
  • 41
Ali Baghdadi
  • 648
  • 1
  • 5
  • 17
  • Yes I tried but it shows error **Unable to update the EntitySet 'cars' because it has a DefiningQuery and no element exists in the element to support the current operation.** – user2516261 Jul 05 '13 at 12:40
  • have you added a primary key to your table in the database? – Ali Baghdadi Jul 05 '13 at 12:43
  • EF won't work with a table without Primary key. http://stackoverflow.com/questions/3996782/entity-framework-table-without-primary-key – HichemSeeSharp Jul 05 '13 at 13:16