entity framework - Loading related objects without Include() -
entity framework - Loading related objects without Include() -
briefly, i'm loading objects descend base of operations class using repository defined against base of operations class. although objects created right descendant classes, descendant classes add together navigation properties not nowadays in base of operations class not have related objects loaded, , have no way explicitly request them.
here simple method in repository class loads given calendar event assuming know id value:
public calendarevent getevent(int eventid) { using (var context = new calendareventdbcontext(connectionstring)) { var result = (from evt in context.calendarevents eventid.equals((int)evt.eventid) select evt).tolist(); homecoming result.tolist()[0]; } }
calendarevent
base of operations class big number of more specific classes descend. entity framework correctly determines actual class of calendar event specified eventid
, constructs , returns derived class. works perfectly.
now, however, have descendant of calendarevent
called reportissued
. object has reference object called reportrequest
(another descendant of calendarevent
, although don't think that's important).
my problem when entity framework creates instance of reportissued
on behalf always want create , load related instance of reportrequested
, because creating event in context of generic calendar events, although correctly reportissued
event, cannot specify .include()
related object. want through generically-expressed search because won't know type of eventid
's event , have several other "get" methods homecoming collections of calendarevent
descendants.
i create mappings using fluent api. guess i'm looking way express, in mapping, related object wanted or, failing that, kind of decorator expresses same concept.
i find odd when saving objects entity framework walks entire graph whereas not equivalent when loading objects.
entity-framework
Comments
Post a Comment