LINQ query syntax to method syntax?

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 ).

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).

Thanks Jon for you explanation and link. Have a nice day! – GibboK Mar 10 at 11:35 I posted a question, I would like you expert opinion if you have time.Stackoverflow.Com/questions/5260346/… thanks in advance for your help.

– GibboK Mar 10 at 13:41.

The following example shows a simple query expression and the semantically equivalent query written as a method-based query. The output from the two examples is identical. You can see that the type of the query variable is the same in both forms: IEnumerable.

To understand the method-based query, let's examine it more closely. On the right side of the expression, notice that the where clause is now expressed as an instance method on the numbers object, which as you will recall has a type of IEnumerable. If you are familiar with the generic IEnumerable interface, you know that it does not have a Where method.

However, if you invoke the IntelliSense completion list in the Visual Studio IDE, you will see not only a Where method, but many other methods such as Select, SelectMany, Join, and Orderby. These are all the standard query operators. Although it looks as if IEnumerable has been redefined to include these additional methods, in fact this is not the case.

The standard query operators are implemented as a new kind of method called extension methods. Extensions methods "extend" an existing type; they can be called as if they were instance methods on the type. The standard query operators extend IEnumerable and that is why you can write numbers.

To get started using LINQ, all that you really have to know about extension methods is how to bring them into scope in your application by using the correct using directives. This is explained additionally in How to: Create a LINQ Project. From your application's point of view, an extension method and a regular instance method are the same.

For more information about extension methods, see Extension Methods (C# Programming Guide). For more information about standard query operators, see Standard Query Operators Overview. Some LINQ providers, such as LINQ to SQL and LINQ to XML, implement their own standard query operators and additional extension methods for other types besides IEnumerable.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions