如何在 LINQWhere 子句中搜索集合的集合?
我有以下 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") _
Where p.Services.Id = ServicesId _
And p.Keywords.Status = KeywordStatus _
Select p
Where 子句无法以这种方式搜索 p.Services 和 p.Keywords EntityCollections。
“Id”不是以下成员的成员 'System.Data.Objects.DataClasses.EntityCollection(Of ....服务)'。
执行我想要的操作的正确 LINQ 语法是什么?
I've got the following ADO.NET Entity Framework Entity Data Model:
I want to find all the Policyholders with both a Service of a given Id and also a Keyword of a given Status.
This LINQ Does Not Work:
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
The Where clause cannot search the p.Services and p.Keywords EntityCollections in that way.
'Id' is not a member of
'System.Data.Objects.DataClasses.EntityCollection(Of
....Service)'.
What is the correct LINQ syntax to do what I want?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
为什么你的查询不起作用? 因为
p.Services
和p.Keywords
是Service
和Keyword
集合 - 它们没有属性Id
或Status
因此您不能使用p.Services.Id
或p.Keywords.Status
。视觉基础...
Why does your query not work? Because
p.Services
andp.Keywords
are aService
and aKeyword
collection - they have not propertyId
orStatus
hence you cannot usep.Services.Id
orp.Keywords.Status
.Visual Basic…