AddObject required in Entity Framework?

I am using the Entity Framework (first time) in a SQL 2005 database to migrate data and found this very strange behavior ...

So far, I have never had to call the AddObject method to save new records. SaveChanges always did the trick, so I decided that the entity constructor always binds the new object to the data context.

Now I have added migration for another type of entity, and suddenly only about 20% of these records are saved, so now I need to call the AddObject method for this type of entity. Can anyone explain how this works?

+3
source share
1 answer

, Entity Framework , (, ) .

:

var myEntity = new MyEntity { Name = "name" }; // will not implicitly add the entity to the context
var myEntity = new MyEntity { OtherEntity = someAttachedEntity }; // will implicitly add the entity to the context
+2

Source: https://habr.com/ru/post/1747319/


All Articles