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:
and their entity sets:
and navigation properties:
Do you know how to do it? I tried for more that one day but I cannot solve it!
Thanks for your time!
The equivalent method syntax is:
var queryContents = context.CmsContentsAssignedToes
.Where(a => a.UserId == myUserGuid)
.Join(context.CmsContents,
a => a.ContentId,
cnt => cnt.ContentId,
(a, cnt) = new { a, cnt })
.Where(z => z.cnt.TypeContent == myTypeContent &
z.cnt.ModeContent == myModeContent)
.Select(z => z.cnt);
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).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With