EF AddOrUpdate Seed does not Update Child Entities

拟墨画扇 提交于 2019-12-03 23:25:00

No command in EF automatically updates child - AddOrUpdate is no difference, it internally check existence of the top level entity (Junk in your case) and insert or update it if it doesn't exist. The insertion of children is a side effect in this case because when AddOrUpdate internally calls Add it adds whole object tree. AddOrUpdate does really much less magic than people expect but even with this small amount of magic it should be used only in migration seeding because it is quite expensive operation (additional roundtrip to database for every entity and a lot of reflection).

Child must always be updated separately - it may require your own separate queries to database to find correct child and common EF update.

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