实体框架 – 实体框架 – Linq To Entities – 多对多查询问题
发布时间:2020-12-12 08:39:52 所属栏目:MsSql教程 来源:网络整理
导读:我在查询 Linq To Entities中的多对多关系时遇到问题. 我基本上尝试使用Linq复制此查询: Select * FROM Customer LEFT JOIN CustomerInterest ON Customer.CustomerID = CustomerInterest.CustomerIDLEFT JOIN Interest ON CustomerInterest.InterestID = In
我在查询
Linq To Entities中的多对多关系时遇到问题.
我基本上尝试使用Linq复制此查询: Select * FROM Customer LEFT JOIN CustomerInterest ON Customer.CustomerID = CustomerInterest.CustomerID LEFT JOIN Interest ON CustomerInterest.InterestID = Interest.InterestID WHERE Interest.InterestName = 'Football' 我环顾网络并没有找到任何合适的例子来说明这一点.我最接近的是: List<Customer> _Customers = (from _LCustomers in _CRM.Customer.Include("CustomerInterest.Interest") where _LCustomers.CustomerInterest.Any(x => x.Interest.InterestName == "Football") select _LCustomers).ToList(); 这样做的问题是,如果客户有多个兴趣而其中一个是“足球”,则返回所有这些兴趣.我也看过All()哪个有逆问题,即只有他们有一个兴趣才会返回,而且只有足球,如果他们有两个,而其中一个不是足球,则不返回. 有人有任何想法吗? 解决方法试试这个,var result = from c in ctx.Customer from i in c.Interest where i.InterestName == "Football" select c; 希望这可以帮助, 射线. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |