Last post Sep 18, 2015 02:44 AM by Mikesdotnetting
Sep 17, 2015 09:34 PM|TheNutCracker|LINK
If I have an Entity with multiple relationships, lets say 5, in total. But initially I only want to load 3 of those relationships, so I use the .Include() method of a DbQuery<> which gets me a single entity.
So, I didn't choose to fully populate my entity, however, Entity Framework appears to always populate the related(foreign keys) of an Entity regardless of whether or not you chose to populate the related entities all at the time of instantiation(isn't this
a word Microsoft? Please put it on the whitelist, and put the word "whitelist" on the whitelist at the same time).
So my question is, simply, can I trigger the instantiation of related entities at a later time without performing a new query on the database without doing a search for the entity myself?
So, I know of 2 different ways to do this already but it seems like there should be a 3rd way. Just by saying, "Hey, I already got the key, just instantiate the relationship for me now".
Edit: LazyLoadingEnabled = true on my context.
Edit: Okay, I figured this out. I remember from this from awhile back. You can't trigger a related Entity load from a single Entity. It looks like you have to trigger the entire related Entity set by enumerating it. Then the related entities will be available.
Sep 18, 2015 02:44 AM|Mikesdotnetting|LINK
General recommended practice for a web application is to turn off lazy loading and eagerly load any related data using Include.
It looks like you have to trigger the entire related Entity set by enumerating it. Then the related entities will be available.