Is query to new added object possible in MS Entity Framework

≯℡__Kan透↙ 提交于 2019-12-05 10:41:28

In EF, if you use this code, you have all the entities that are already loaded in the context (including newly added ones) :

context.ObjectStateManager.GetObjectStateEntries(EntityState.Added | EntityState.Modified | EntityState.Unchanged).Select(o => o.Entity).OfType<YourObjectType>()

"The same question also applies to LinqToSql."

For LINQ-to-SQL, look at DataContext.GetChangeSet(); this has 3 separate collections for the pending .Inserts, .Updates and .Deletes

Note that the ChangeSet is a snapshot of when the GetChangeSet() method is called; you need to re-query to see any additional changes.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!