Entity Framework - restoring navigation property after detaching entities

.net entity-framework entity-framework-6 lazy-loading objectcontext

Question

Lazy loading is enabled in my Entity Framework model (using EF 6.1 with ObjectContext), which also includes a number of navigation settings.

For instance:

// Orders is a navigation property (collection), which, when first iterated,
// loads the collection of Order entities from the DB
var orders = Customer.Orders.ToList();

I wish to have a detachable component in my app for performance reasons.Order entities and let them to be discarded:

MyContext.Detach(order1);
MyContext.Detach(order2);
MyContext.Detach(order3);

However, I've discovered that when I merely disconnect a portion of the child entities—that is, not all of them—the following repetition ofCustomer.Orders It not function since the detached entities are not included in the collection that is returned.

How can I build code to obtain theCustomer.Orders causing it to reload and re-attach all entities, including those that were previously detached, in order for the navigation property to recover and function properly in this circumstance?

I've tried adjusting things manuallyCustomer.Orders.IsLoaded to false , however it doesn't work either. Somewhere inside of EF, the entities are not re-loaded.IsLoaded it just resets totrue .

1
1
11/14/2017 2:50:44 PM

Accepted Answer

ZZZ_tmp
1
11/11/2017 9:45:27 AM

Popular Answer

ZZZ_tmp


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow