开发者

How to determine if the relationships in an entity collection have been saved to the database

I have a situation where I'm adding existing entities to an entity collection. Before calling "context.SaveChanges()", I need to know which entities in the entity collection have not had their relationship saved in the database. There's no point in checking the "EntityState" property of each entity in the collection because they are all "Unchanged" (remember, the entities already exist in the database). I should mention that the typ开发者_Python百科e of relationship is "many-to-many"...basically, I want to know if a row has been added to the "many-to-many" relationship table.


I'm not aware of a way to accomplish just that what you ask, but it may be of help - you can see which entities have been changed by inspecting contents of DBContext.ChangeTracker.Entries(), where every entry has reference to the changed entity object. This collection should contain all new/modified/deleted records in any, including your many-to-many relationship table.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜