EF4 and undesired loading of related collection with AddObject

我是研究僧i 提交于 2019-11-28 09:26:49

I guess you are using POCO T4 template which suspects exactly this behavior. The problem are fixup methods generated by POCO template. Every time you assign navigation property, foreign key or add object to collection of related objects these methods performs object graph fixup. It means they update navigation on related entity as well. In your scenario it means that fixup methods adds Request to Requests collection in the Session. Access to the collection will trigger lazy loading. The only ways to avoid this are:

  • Turn off lazy loading for this operation (context.ContextOptions.LazyLoadingEnabled = false)
  • Remove Requests property from Session
  • Modify T4 template and remove fixup methods
  • Modify T4 template and remove virtual from Requests property (Session will not support lazy loading)
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!