Linq convert a Method Syntax to Query Expression
Recently I wrote this query with Linq (Method Syntax),开发者_如何转开发 notes:
g.CmsContents
is a Navigatiola Property.
I would like to know how to rewrite this code as a Linq Query Expression if it is possible.
var myGroupsTypesList = from g in context.CmsGroupsTypes
where g.CmsContents.Any(x => x.ContentId == myContentId)
select g;
Any idea? Thanks for your support :-)
That's already a query expression. If you mean you want to convert the Any
part to another query expression - you can't. There's no query expression support for Any
.
If you actually meant it the other way round, your query is equivalent to:
var myGroupsTypesList = context.CmsGroupsTypes
.Where(g => g.CmsContents.Any(x => x.ContentId == myContentId));
精彩评论