1

以下代码对我有用:

var query0 = DB.Plan
    .Include("UserCreate")
    .Include("UserUpdate")
    .Include("PlanTemplate")
    .Select(p => new
            {
                plan = p,
                planItems = p.PlanItems.Where(pi => pi.IsCommited == true && pi.IsLocked ==    false)
            });
var query2 = query0.AsEnumerable().Where(m => m.planItems.Count() > 0).Select(m => m.plan);

但是与我想要的另一个实体相关的 planItems,以下代码对我不起作用:

var query0 = DB.WorkEffortPlan
.Include("UserCreate")
.Include("UserUpdate")
.Include("PlanTemplate")
.Select(p => new
{
    plan=p,
    planItems = DB.PlanItem
    .Include("UserResponsiblePerson")
    .Include("TemplateItem")
    .Include("ItemState")
    .Where(pi => pi.PlanID == p.PlanID && pi.IsCommited == true && pi.IsLocked == false)
});
var query2 = query0.AsEnumerable().Where(m => m.planItems.Count() > 0).Select(m => m.plan);

vs 编译器运行正常,但是当执行此代码时,我在 query0 中得到 NullReferenceException。

是否有任何 linq 解决方案来过滤子实体及其相关实体?

4

0 回答 0