entity framework 4 - POCO entities and IsLoaded() in EF 4.1 -
i'm working on enterprise application leverages repository pattern on top of ef 4.1 eager loading poco entities. typically, call this:
public ienumerable<someentity> list(datetime date) { using (var context = contextfactory.createcontext()) // returns dbcontext { return createquery<someentity>(context) .include("path1") .include("path2") .where(...) .asnotracking() .tolist(); } } at point, business layer translates these entities dtos transmitted via wcf web application.
as eager loading rather expensive, i'm trying keep .include's minimum, related properties (eagerly) loaded , they're not. however, business layer has no idea when related properties present in entity, objectcontextdisposedexception, reason clear me , don't intend change basic strategy (i.e. dispose context right after eager loading entities).
however, need check whether particular related property loaded or not, checking if related object null doesn't work (objectcontextdisposedexception), nor there kind of isloaded() method use.
am stuck try/catch block here or there other options?
turn off lazy loading , check null work. current solution cannot use lazy loading because dispose context after running query:
context.configuration.lazyloadingenabled = false;
Comments
Post a Comment