我試圖讓我所有的maingroups及其相關實體。我還想過濾BuildingPartData集合而不影響任何其他實體。我幾乎想盡辦法想,但沒有運氣。EF 4過濾子集合
test.ContextOptions.LazyLoadingEnabled = false;
var buildingPartMainGroups = (from buildingPartMainGroup in test.BuildingPartMainGroup
from buildingPartSubGroup in buildingPartMainGroup.BuildingPartSubGroup
from buildingPart in buildingPartSubGroup.BuildingPart
from buildingPartData in buildingPart.BuildingPartData
where buildingPartData.StatusPendingApprove == true
//let buildingPartData = buildingPartMainGroup.BuildingPartSubGroup.Where(x => x.BuildingPart.Any(o => o.BuildingPartData.Any(y => y.StatusPendingApprove == true)))
select new
{
BuildingPartMainGroups = buildingPartMainGroup,
BuildingPartDatas = buildingPartData
}).ToList().Select(c => c.BuildingPartMainGroups);
foreach (var bb in buildingPartMainGroups)
{
foreach(var tt in bb.BuildingPartSubGroup)
{
foreach (var oo in tt.BuildingPart)
{
foreach (var ww in oo.BuildingPartData)
{
bool tes4t = ww.StatusPendingApprove;
}
}
}
}
這裏是模型
http://mimo-design.com/model.png
廣東話插入圖片尚未..
var buildingPartMainGroups = test.BuildingPartMainGroup.Include("BuildingPartSubGroup.BuildingPart.BuildingPartData").
Where(bpmg => bpmg.BuildingPartSubGroup.
Any(o => o.BuildingPart.
Any(x => x.BuildingPartData.
Any(u => u.StatusPendingApprove == true))));
只過濾我BuildingPartMainGroup實體。我想有我所有的BuildingPartMainGroup實體,符合條件/過濾器上BuildingPartData
有關對象模型/實體模型的更多文檔可能會更好。 –
新增型號:-) – mimo
這說明了很多。看到我的第二個答案! –