如何过滤包含的导航属性集合? [英] How to filter included Navigation Property Collection?

查看:69
本文介绍了如何过滤包含的导航属性集合?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在过滤包含的实体方面遇到了一些问题。

I have a little problem with filtering included entities.

 

有两个表:

表1

{

Table1_Id;

Table1_Id;

名称;

}

Name;
}

 

表2

{

Table1_Id; (FK)

Table1_Id; (FK)

SpecificProperty;

SpecificProperty;

日期;

}

Date;
}

 

所以,在EF I'中获得下一个实体:

So, in EF I've got next Entity:

 

Table1Entity

Table1Entity

{

Table1_Id;

Table1_Id;

名称;

Table2_Entities; (导航属性 - 收藏)

}

Table2_Entities; (Navigation Property - Collection)
}

 

问题:如何选择包含Table2的所有Table1实体实体并过滤它们,只留下最后一项,例如,最大日期?

Question: How to select ALL Table1 entities with included Table2 entities and filter them, to leave only 1 last item, for example, with Max Date?

喜欢:MyContext.Table1.Include(" Table2_Entities")。//包含的一些过滤  ;表2 _Entities。

Like: MyContext.Table1.Include("Table2_Entities").//some filtering of included Table2_Entities.

 

非常感谢!

 

 

推荐答案

这样的事情应该有效:

Something like this should work:

 


var query = 
from t in dc.Table1_Entities
select new 
{
 t1 = t
 t2 = from table2 in t.Table2_Entities where table2.MaxDate > ...
}
     
var result = query.AsEnumerable().Select( t=>t.t1 ).


这篇关于如何过滤包含的导航属性集合?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆