Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/linq/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Linq 如何使用include加载集合_Linq_Entity Framework_Include - Fatal编程技术网

Linq 如何使用include加载集合

Linq 如何使用include加载集合,linq,entity-framework,include,Linq,Entity Framework,Include,如何使用include加载集合,我已尝试了以下方法: Type.Wheret=>t.Entity.Wheree=>e.Parent==false.Count>0.Includee=>e.Entity 但此处不支持筛选器,因为恢复的实体不满足条件 使用LinQ To实体: var v = from type in ObjectContext.Type from entity in Type.Entities where entity.Parent == false

如何使用include加载集合,我已尝试了以下方法:

Type.Wheret=>t.Entity.Wheree=>e.Parent==false.Count>0.Includee=>e.Entity

但此处不支持筛选器,因为恢复的实体不满足条件

使用LinQ To实体:

var v = from type in ObjectContext.Type
        from entity in Type.Entities
        where entity.Parent == false
        select type;
但类型不包含其关联的实体

我不能编写选择新类型{Type.Code,Type.Entities},也不能使用匿名类型,因为它不适合我的存储库层

你对如何获得属性实体满足条件的类型对象列表有什么想法吗

更新

谢谢你的回复

我认为使用CTP不是个好主意,不是吗

对不起,我没有解释我的对象模型,我有:

class Type {
  public string Code { get; set; }
  public IList<Entity> Entities { get; set; }
  ...
}

class Entity {
  public string Code { get; set; }
  ...
}
我想使用你的第二个过滤建议:过滤两个实体集

不使用CTP,您有什么建议吗

谢谢
Rad

正如您所说,您希望对相关实体应用过滤器,最好查看EF4的新CTP5
当显式加载相关实体时,请查看“应用过滤器”下的内容

如您所述,您希望将过滤器应用于相关实体,最好查看EF4的新CTP5
在显式加载相关实体时,请查看“应用过滤器”下的内容

您是在尝试包含所有相关实体,还是在包含时也要应用过滤器?您好,伊万诺夫,我希望在包含时也应用过滤器欢迎使用堆栈溢出。请简单地编辑您的问题,单击编辑链接添加其他信息,或使用评论回复您收到的答案。答案字段严格保留用于答案。请查看此问题的答案:。使用此处建议的CreateSourceQuery,它需要到DB的两次往返,但CTP解决方案也需要两次往返。当您使用Include只访问数据库一次时,似乎无法将筛选器应用于导航属性。您是在尝试包含所有相关实体,还是在包含时也要应用筛选器?您好,Ivanov,我希望在包含时也应用筛选器欢迎使用堆栈溢出。请简单地编辑您的问题,单击编辑链接添加其他信息,或使用评论回复您收到的答案。答案字段严格保留用于答案。请查看此问题的答案:。使用此处建议的CreateSourceQuery,它需要到DB的两次往返,但CTP解决方案也需要两次往返。当您使用Include只访问数据库一次时,似乎不可能对导航属性应用过滤器。