LINQ 查询语法到方法语法
我使用 asp.net、c# 和 EF4。
我对这个 LINQ 查询感到困惑:
var queryContents = from a in context.CmsContentsAssignedToes
where a.UserId == myUserGuid
join cnt in context.CmsContents
on a.ContentId equals cnt.ContentId
where cnt.TypeContent == myTypeContent & cnt.ModeContent == myModeContent
select cnt;
我想用 LINQ 方法语法 编写其等效项来检索 CmsContents。
在我的概念模型中有两种实体类型:
- CmsContent
- CmsContentsAssignedTo
及其实体集:
- CmsContents
- CmsContentsAssignedToes
和导航属性:
- 在 CmsContent --> 中CmsContentsAssignedTo RETURN: --> CmsContentsAssignedTo 中的 CmsContentsAssignedTo 实例
- --> CmsContent 返回: --> CmsContent 实例
你知道怎么做吗?有一天我尝试了更多,但无法解决!
感谢您抽出时间!
I use asp.net, c# and EF4.
I'm puzzled by this LINQ query:
var queryContents = from a in context.CmsContentsAssignedToes
where a.UserId == myUserGuid
join cnt in context.CmsContents
on a.ContentId equals cnt.ContentId
where cnt.TypeContent == myTypeContent & cnt.ModeContent == myModeContent
select cnt;
I would like write its equivalent in LINQ method syntax to retrieve CmsContents.
In my conceptual model are two entity types:
- CmsContent
- CmsContentsAssignedTo
and their entity sets:
- CmsContents
- CmsContentsAssignedToes
and navigation properties:
- in CmsContent --> CmsContentsAssignedTo RETURN: --> Instance of CmsContentsAssignedTo
- in CmsContentsAssignedTo --> CmsContent RETURN: --> Instance of CmsContent
Do you know how to do it? I tried for more that one day but I cannot solve it!
Thanks for your time!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
等效的方法语法是:
请参阅我的 Edulinq 关于查询表达式的博客文章,了解其工作原理的更多详细信息,特别是“z”的来源(它并不是真正的“z”;它并不被称为“z”)没有名称,因为它是一个透明标识符)。
The equivalent method syntax is:
See my Edulinq blog post on query expressions for more details of how this works, and particularly where the "z" comes from (it's not really called "z"; it doesn't have a name as it's a transparent identifier).