C# 林克:里面包括什么

C# 林克:里面包括什么,c#,linq,repository,C#,Linq,Repository,我有一个父表(InventoryItem)和另一个子表(InventoryItemLines),每个父表可以有一个未确定数量的子表 我需要得到所有的父母,对于每个父母,我需要得到尊重特定条件的孩子的名单 示例:我在子表中有一个“非活动”位列,我使用此语句获取数据: “\u存储库是一个IRepository var entities = _repository.GetAsQueryable().Include(x => x.InventoryItemLines.Where(i => i

我有一个父表(InventoryItem)和另一个子表(InventoryItemLines),每个父表可以有一个未确定数量的子表

我需要得到所有的父母,对于每个父母,我需要得到尊重特定条件的孩子的名单

示例:我在子表中有一个“非活动”位列,我使用此语句获取数据: “\u存储库是一个IRepository

var entities = _repository.GetAsQueryable().Include(x => x.InventoryItemLines.Where(i => i.Inactive));
但是我收到一条ArgumentException消息:“Include path表达式必须引用在类型上定义的导航属性。使用虚线路径作为参考导航属性,选择运算符作为集合导航属性。 参数名称:路径“


你能告诉我这种情况下的好方法吗?

代码如下所示

使用系统;
使用System.Collections.Generic;
使用System.Linq;
使用系统文本;
使用系统数据;
命名空间控制台应用程序1
{
班级计划
{
静态void Main(字符串[]参数)
{
DataTable InventoryItem=新DataTable();
InventoryItem.Columns.Add(“Item”,typeof(string));
添加(新对象[]{“Shoes”});
添加(新对象[]{“Ties”});
InventoryItem.Rows.Add(新对象[]{“连衣裙”});
DataTable InventoryItemLines=新DataTable();
InventoryItemLines.Columns.Add(“Item”,typeof(string));
InventoryItemLines.Columns.Add(“Color”,typeof(string));
InventoryItemLines.Columns.Add(“Active”,typeof(Boolean));
添加(新对象[]{“Shoes”,“Red”,true});
添加(新对象[]{“Shoes”,“Blue”,true});
InventoryItemLines.Rows.Add(新对象[]{“Shoes”,“Turquoise”,false});
添加(新对象[]{“Ties”,“Red”,true});
添加(新对象[]{“Ties”,“Stripped”,true});
添加(新对象[]{“Ties”,“Pokerdot”,false});
添加(新对象[]{“连衣裙”,“黄色”,true});
添加(新对象[]{“连衣裙”,“蓝色”,true});
InventoryItemLines.Rows.Add(新对象[]{“连衣裙”,“紫罗兰色”,true});
添加(新对象[]{“Tresses”,“Stripped”,false});
var results=InventoryItem.AsEnumerable()。选择(x=>new
{
项目=x.字段(“项目”),
inactive=InventoryItemLines.AsEnumerable()。其中(y=>(y.Field(“Item”)==x.Field(“Item”)&&&!y.Field(“Active”)。ToList()
}).ToList();
}
}
}

代码看起来像这样

使用系统;
使用System.Collections.Generic;
使用System.Linq;
使用系统文本;
使用系统数据;
命名空间控制台应用程序1
{
班级计划
{
静态void Main(字符串[]参数)
{
DataTable InventoryItem=新DataTable();
InventoryItem.Columns.Add(“Item”,typeof(string));
添加(新对象[]{“Shoes”});
添加(新对象[]{“Ties”});
InventoryItem.Rows.Add(新对象[]{“连衣裙”});
DataTable InventoryItemLines=新DataTable();
InventoryItemLines.Columns.Add(“Item”,typeof(string));
InventoryItemLines.Columns.Add(“Color”,typeof(string));
InventoryItemLines.Columns.Add(“Active”,typeof(Boolean));
添加(新对象[]{“Shoes”,“Red”,true});
添加(新对象[]{“Shoes”,“Blue”,true});
InventoryItemLines.Rows.Add(新对象[]{“Shoes”,“Turquoise”,false});
添加(新对象[]{“Ties”,“Red”,true});
添加(新对象[]{“Ties”,“Stripped”,true});
添加(新对象[]{“Ties”,“Pokerdot”,false});
添加(新对象[]{“连衣裙”,“黄色”,true});
添加(新对象[]{“连衣裙”,“蓝色”,true});
InventoryItemLines.Rows.Add(新对象[]{“连衣裙”,“紫罗兰色”,true});
添加(新对象[]{“Tresses”,“Stripped”,false});
var results=InventoryItem.AsEnumerable()。选择(x=>new
{
项目=x.字段(“项目”),
inactive=InventoryItemLines.AsEnumerable()。其中(y=>(y.Field(“Item”)==x.Field(“Item”)&&&!y.Field(“Active”)。ToList()
}).ToList();
}
}
}

基本上你做不到,没有办法使用EF有条件地包含相关实体。你做不到,你必须使用投影来实现这一点。基本上你做不到,没有办法使用EF有条件地包含相关实体。你做不到,你必须使用投影来实现这一点