使用 EF 4 和 RIA 服务连接两个表并筛选结果
Public Function LoadSiteInfo(ByVal sId As Integer) As IQueryable(Of Site)
Return Me.ObjectContext.Sites.Include("SiteData").Where((Function(f) f.SiteID = sId) AndAlso Function(x) x.SiteData.SiteUpdateDate < today))
End Function
因此,我试图从 Sites 表中过滤 SiteId,并在 SiteData 表中的 SiteUpdateDate 上进行过滤,这是我无法获得正确语法的最后一部分 - 它只是说 SiteUpdateDate 属性不是 ObjectContext.Site 的成员,这是正确的 SiteData 部分
如何过滤包含的表 SiteData 中的属性?或者我如何重写它并仍然返回一个可查询的站点,其中 SiteData 子表已根据我的需要进行过滤?应该很容易,但我很挣扎,开始相信不允许包含选定父级的过滤子集合......:(
Public Function LoadSiteInfo(ByVal sId As Integer) As IQueryable(Of Site)
Return Me.ObjectContext.Sites.Include("SiteData").Where((Function(f) f.SiteID = sId) AndAlso Function(x) x.SiteData.SiteUpdateDate < today))
End Function
So, I'm trying to filter on SiteId from the Sites table, ANDALSO on the SiteUpdateDate in the SiteData table, it's the last part where I cannot get the syntax correct - it's just saying that SiteUpdateDate attribute is not a member of ObjectContext.Site, which is correct its part of SiteData
How can I filter on attributes in the included table SiteData? Or how can I rewrite this and still return an Iquerable of Site with SiteData childtable beeing filtered as I want? Should be really easy, but I'm struggling, starting to believe that include a filtered child collection of a selected parent is not allowed... :(
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不相信你可以这样做。您必须首先将子集合返回给您的父集合。
那应该对你有用。
您还需要检查您的 RIA 服务,以确保您的子集合具有 [include] 作为属性。
I dont believe you can do it this way. You have to first return your parent with child collections.
That Should work for you.
also you need to check your RIA services to make sure your Child Collection has [include] as an attribute.
我不太擅长 VB,所以这里是 C# 版本。
技巧是,您无法过滤急切加载的属性 (
SiteData
),因此您必须使用匿名类型投影,然后将查询投影回您想要的内容。I'm not good with VB, so here's the C# version.
The trick is, you can't filter on an eager loaded property (
SiteData
), so you have to use anonymous type projection, and then project the query back into what you want.