Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What am I using? (Linq/sql) [duplicate]

Tags:

c#

linq

My project currently uses for following syntax for "linq"

 var le = domainModel.EntityDataContext.Table_name_here.Query()
                    .WithFullReadCheck(domainModel.Security)
                    .Where(x => x.Metadata.AdvisorID == advisorId).FirstOrDefault();

It is said the above code is linq, being unaware about linq I decided to learn it. However, on https://msdn.microsoft.com/en-us/library/gg509017.aspx , things are pretty different.

what is being used in my code? Is it a version of linq? Is it something else?

like image 611
Indigo Avatar asked Jul 31 '26 21:07

Indigo


2 Answers

What you are using is LINQ. There are 2 different notations you can use for writing LINQ - Lambda Syntax and Query Syntax

The difference is explained here: LINQ: Dot Notation vs Query Expression

There is more information on this on MSDN here: https://msdn.microsoft.com/en-us/library/bb308959.aspx

The MSDN articles starts explaining LINQ with SQL-like syntax ("query syntax") and then goes on to explain Lambda Expressions and Expression Trees ("lamba syntax").

like image 167
Russ Penska Avatar answered Aug 03 '26 12:08

Russ Penska


That is extension method syntax for a query. The .Query().WithFullReadCheck() are much less common, but the rest .Where and .FirstOrDefault are pretty common query extensions. LINQ is a special syntax for expressing the same thing that can be done with chaining the query extension methods. Behind the scenes, they are identical.

See this question which gives an example of both LINQ and extension method syntax and has a good discussion of the differences between them: Extension methods syntax vs query syntax

like image 32
AaronLS Avatar answered Aug 03 '26 11:08

AaronLS



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!