我有三张桌子。事件、根本原因和IncidentRootCauses。表意外熵原因与事件是一对多的关系。当我获得事件对象时,没有我所期望的根本原因对象的列表,相反,我得到(在我的即时窗口中)
var rt = incident.IncidentRootCauses;{System.Data.Linq.EntitySet}计数:1
HasLoadedOrAssignedValues: true
IsDeferred: false我希望能够在查询运行时加载所有的rootcause对象。我知道问题在于事件并没有显式地绑定到根本原因表。感谢你在这方面的帮助。
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;
}发布于 2012-09-11 00:02:12
听起来你还想要一个二级的急切加载的实体。
在同一LoadOptions上,尝试:
lo.LoadWith<IncidentRootCause>(irc => irc.RootCause);发布于 2012-09-11 01:24:42
您可能需要检查生成的SQL。当尝试加载多个子级时,某些load with options可能会被忽略,因为这可能意味着拉取太多记录。因此,在退出using子句之前,可能无法拉取子记录中的某些记录。
https://stackoverflow.com/questions/12355125
复制相似问题