Matt
Matt

Reputation: 6953

Entity Framework: ObjectSet.AddObject not adding the entity?

I am using EF4 in VS2010 and I have the following code:

MyEntity entity = null;
entity = MyEntity.CreateMyEntity(0);
context.MyEntities.AddObject(entity);
context.AcceptAllChanges();
context.SaveChanges();

The problem is that AddObject() is not adding the object to the collection and I just can't figure out why. What happens when I step through the code is that it gets to the first property, "CityId" which is of course null and then it seems to just return from there... like it had a problem with the property being null. The only non-nullable field in my database (MSSQL) is the Id column, which is an identity column... I am quite perplexed. Please help!

Thanks in advance!

Matt

Upvotes: 0

Views: 1889

Answers (1)

Akash Kava
Akash Kava

Reputation: 39916

You are not supposed to call accept all changes method.

Upvotes: 1

Related Questions