将新项目添加并保存到DbContext时,传递给Add方法的项目会自动获取正确的Id。实体框架如何将Id的值传递给传递的对象?
(此处答案中显示的代码段:How can I get Id of inserted entity in Entity framework?)
using (var context = new MyContext())
{
context.MyEntities.AddObject(myNewObject);
context.SaveChanges();
int id = myNewObject.Id; // Yes it's here
}
基本上,Id的值是如何插入myNewObject的?