Insert Query in Linq to SQL

LINQ Lambda Expression query with Examples

A Lambda expression is an anonymous function that we can use to create expression tree types, delegates etc.

A lambda expression is an expression on the right side of the => operator is called an expression lambda. It is also called (=>) goes to operator.

Syntax:  (Input parameters) => Expirations or Statement block

A Lambda expression is particularly helpful for writing LINQ query expressions.

A lambda expression is powerful, shorter and suitable tool.

Personally, I prefer to lambda extensions for most code writing. I am only using the statements if I am doing LINQ to SQL otherwise I am trying to emulate SQL. I find that the lambda methods flow better with code whereas the statements are visually distracting.

So, here I am trying to explain gather T-SQL queries along with their LINQ queries with lambda expressions.

EmpEntites empEnt = new EmpEntites();  //This is entities objects.

In these entities objects, we have a table “tbl_Employee” and I am trying to explain T-SQL queries with their LINQ queries with lambda expressions.

Now, I get all the records from “tbl_Employee” which are sorted by EmpId ascending i.e.
var result = empEnt.tbl_Employee.OrderBy(x=>x.EmpId).ToList(); // This is Lambda.

Now, I get all the records from “tbl_Employee” which are sorted by EmpId descending i.e.
var result = empEnt.tbl_Employee.OrderByDescending(x=>x.EmpId).ToList(); // This is Lambda.

Remember Points,
1.   A lambda expression is use to execute any unsafe code inside any lambda expression.
2.   A lambda expression can return a value and may have parameters.
3.   A lambda expression is not meant to be used on the operators left side.

I hope this is helpful to you! Thank you!

Hey! I'm Anil Singh. I author this blog. I'm Active Blogger, Programmer. I love learning new technologies, programming, blogging and participating the forum discussions more...
My Blogs - and
My Books - Google Amazon and Flipkart Book Store!

You Might Also Like
Post a Comment Powered by Blogger.
ASK Questions
SQL Server NodeJs TypeScript JavaScript Angular SQL Server My Book