I have an odd case where adding a record is causing unwanted loading of a related collection.
For example, I have Requests and Sessions. A Session can contain many
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:
context.ContextOptions.LazyLoadingEnabled = false
)Requests
property from Session
Requests
property (Session
will not support lazy loading)