LINQ query syntax for method syntax

I am using asp.net, C # and EF4.

I am 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 to write its equivalent in the syntax of the LINQ method for extracting CmsContents.

There are two types of entities in my conceptual model:

  • Cmscontent
  • CmsContentsAssignedTo

and their essence:

  • Cmscontents
  • CmsContentsAssignedToes

and navigation properties:

  • in CmsContent -> CmsContentsAssignedTo RETURN: โ†’ CmsContentsAssignedTo Instance
  • in CmsContentsAssignedTo -> CmsContent RETURN: -> CmsContent instance

Do you know how to do this? I tried to learn more about this, but I canโ€™t solve it!

Thank you for your time!

+4
source share
1 answer

The syntax of the equivalent method 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 in expression expressions for more details on how this works, and especially where โ€œzโ€ happens (this is not actually called โ€œzโ€, it does not have a name as a transparent identifier).

+10
source

Source: https://habr.com/ru/post/1343137/


All Articles