EF 中的子对象过滤器
如何通过某些条件使用实体框架过滤子对象? 例如:我有对象 Company 和 ChildObjects,CompanyChilds。 CompanyChilds 拥有活跃的财产。我想要获得具有准确 ID 的公司和具有 active 等于 true 的子对象。
我尝试过这个:
dbContext.Company.Include("ChildCompany").Where(x => x.Id == Id
&& x.ChildCompany.Any(y => y.Active == true));
欢迎任何帮助:)
How can I filter child objects with entity framework by some criteria?
For example: I have object Company with ChildObjects, CompanyChilds. CompanyChilds have property active. I want to get Company with exact ID and Child Objects with active equals true.
I tried with this:
dbContext.Company.Include("ChildCompany").Where(x => x.Id == Id
&& x.ChildCompany.Any(y => y.Active == true));
Any help is welcome :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
有一种方法可以在 Code First API 中过滤子记录 - 请参阅这篇文章:
There is a way to filter child records in the Code First API -- see this post:
http://blogs.msdn.com/b/adonet/archive/2011/01/31/using-dbcontext-in-ef-feature-ctp5-part-6-loading-related-entities.aspx
See "Applying filters when explicitly loading related entities"
假设您基本上想要来自母公司的活跃子级。
但是,您也许可以直接查询子级。
Presuming that you basically want the active children from the parent company..
However, you may be able to query the children directly..