Entities AddObject or SaveChanges
I would like to know a bit more about how the entity framework works. I have a collection of MyEntity
being displayed in a combobox. The user has the option of editing the selected item or adding a new item by clicking a button. In my view model if I just hit save changes on a new object of MyEntity
I get an error, but if I add the object first then its ok. Is there anyway for EF to detect that I have this new object and add it automatically or do I always have to add it expli开发者_StackOverflowcitly?
Entity Framework is just an ORM framework, it cannot detect anything. It is up to you to add the new objects to the context using the Add() method and then call the SaveChanges() method to persist the data...
精彩评论