我有 3 张桌子。事件、根本原因和事件根本原因。表incidentrootcauses 以一对多的方式与事件相关联。当我得到事件对象时,没有我预期的根本原因对象列表,而是得到(在我的即时窗口中)
var rt = incident.IncidentRootCauses;
{System.Data.Linq.EntitySet} 计数:1
HasLoadedOrAssignedValues: true
IsDeferred: false
我希望能够在查询运行时加载所有根本原因对象。我知道问题是事件没有明确地与根本原因表相关联。感谢您对此的任何帮助。
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;
}