Entity Framework and Object Context Lifetime in ASP.NET MVC

I use the Entity Framework in my project, and I have a problem when I pass my objects to the view (keep in mind that these objects have lazily initialized objects according to: Products.Owner, where the owner is an object that is lazily initialized ) I get a runtime exception telling me that the ObjectContext is out of scope.

Now it makes sense, since I get entities from the Service using (.... objects ...) {....}, which means that it is deleted when the result is returned.

How do I get around this and create the context of an object that is alive from start to finish. Thank.

+4
source share
1

, ID- Dispose ObjectContext, .

+2

All Articles