.net 如何在LINQ Where子句中搜索集合的集合?
我得到了以下ADO.NET实体框架实体数据模型: 我想找到所有拥有给定Id服务和给定状态关键字的投保人 此LINQ不工作:.net 如何在LINQ Where子句中搜索集合的集合?,.net,vb.net,linq,entity-framework,lambda,.net,Vb.net,Linq,Entity Framework,Lambda,我得到了以下ADO.NET实体框架实体数据模型: 我想找到所有拥有给定Id服务和给定状态关键字的投保人 此LINQ不工作: Dim ServicesId As Integer = ... Dim KeywordStatus As Integer = ... Dim FoundPolicyholders = From p As Policyholder In db.PolicyholderSet.Include("Keywords").Include("Services") _
Dim ServicesId As Integer = ...
Dim KeywordStatus As Integer = ...
Dim FoundPolicyholders = From p As Policyholder In db.PolicyholderSet.Include("Keywords").Include("Services") _
Where p.Services.Id = ServicesId _
And p.Keywords.Status = KeywordStatus _
Select p
Where子句不能以这种方式搜索p.Services和p.Keywords EntityCollections
“Id”不是的成员
'System.Data.Objects.DataClasses.EntityCollection(共个)
……服务
做我想做的事情的正确LINQ语法是什么
db.PolicyholderSet.Where(ph =>
ph.Services.Any(s => s.Id == someId) &&
ph.Keywords.Any(kw => kw.Status == someStatus))
为什么您的查询不起作用?因为p.Services
和p.Keywords
是Service
和Keyword
集合-它们没有属性Id
或Status
,因此您不能使用p.Services.Id
或p.Keywords.Status
Visual Basic
Dim FoundPolicyholders = From p As Policyholder In db.PolicyholderSet.Include("Keywords").Include("Services") _
Where p.Services.Any(Function(s) s.Id = ServicesId) _
And p.Keywords.Any(Function(k) k.Status = KeywordStatus) _
Select p
为什么您的查询不起作用?因为p.Services
和p.Keywords
是Service
和Keyword
集合-它们没有属性Id
或Status
,因此您不能使用p.Services.Id
或p.Keywords.Status
Visual Basic
Dim FoundPolicyholders = From p As Policyholder In db.PolicyholderSet.Include("Keywords").Include("Services") _
Where p.Services.Any(Function(s) s.Id = ServicesId) _
And p.Keywords.Any(Function(k) k.Status = KeywordStatus) _
Select p
函数“Any”就是我需要的线索。谢谢。函数“Any”就是我需要的线索。非常感谢。