I have 3 tables. Incidents, Rootcauses, and IncidentRootCauses. The table incidentrootcauses is tied to Incidents as a one to many. When I get the Incident object, There is not a list of rootcause objects as a I expected, instead I am getting (In my Immediate window)
var rt = incident.IncidentRootCauses;
{System.Data.Linq.EntitySet}
Count: 1
HasLoadedOrAssignedValues: true
IsDeferred: false
I would like to be able to load all of the rootcause objects when the query runs. I know the problem is that incident is not tied to the rootcause table explicitly. Thank you for any help with this.
using (var db = new IncidentTrackerDataContext())
{
var lo = new DataLoadOptions();
lo.LoadWith<Incident>(incidents => incidents.ReportedTo);
lo.LoadWith<Incident>(incidents => incidents.Shift);
lo.LoadWith<Incident>(incidents => incidents.Machine);
lo.LoadWith<Incident>(incidents => incidents.Department);
lo.LoadWith<Incident>(incidents => incidents.IncidentRootCauses);
lo.LoadWith<IncidentRootCause>(i => i.RootCause);
// lo.LoadWith<Incident>(incidents => incidents.IncidentManagers);
// lo.LoadWith<Incident>(incidents => incidents.IncidentMembers);
// lo.LoadWith<Incident>(incidents => incidents.IncidentWitnesses);
db.LoadOptions = lo;
db.DeferredLoadingEnabled = false;
Incident incident = (from i in db.Incidents
where i.IncidentReportID == new Guid(incidentID)
select i).FirstOrDefault();
return incident;
}
It sounds like you also want a second level of eager loaded entities.
On the same LoadOptions, try: