Hi,/P>
Continuing on my post on Lambda and LINQ, in this post I will talk about how to use the lambda expression in the LINQ query. LINQ query can work great without the Lambda expression. But we can also use Lambda expression in the LINQ query. /p>;
Do check these earlier post of mine on the Lambda expresions and LINQ Query C Sharp 3.0 new Features Lambda Expressions/FONT>/A> Starting with the basic of Lambda Expression/FONT>/A>/SPAN>/SPAN>/SPAN>/SPAN> Some examples on how to use Lambda Expression/FONT>/A> Starting Basic Queries with LINQ/FONT>/A> Using LINQ to get the information about all the methods in a type/FONT>/A> Working with LINQ queries and Inner Join/FONT>/A>/SPAN>/SPAN>/SPAN>/SPAN>/SPAN>/SPAN>/SPAN>/SPAN>/SPAN>/SPAN>/SPAN>/SPAN>In this post I will use the LINQ query from my previous examples/A> and create the same query using Lambda expression. This will help in understanding how can Lambda expressions be useful in writing the LINQ queries./P> Previous LINQ query (Select some fields from a given class using the anonymous types)/P> /SPAN>var t = from c in BlogBLL.Categories/P> /SPAN>select new /P> /SPAN>{/P> /SPAN>c.CategoryID,/P> /SPAN>c.CategoryName/P> /SPAN> /SPAN>};/P> Its Lambda equivalent would be /P> var t = BlogBLL.Categories.Select(c => new {c.CategoryID, c.CategoryName});/P> LINQ query to select some fields from the category class where the categoryId is greater than equal to 5/P> var t = from c in BlogBLL.Categories/P> /SPAN>where c.CategoryID /SPAN><= 5/P> /SPAN>select new /P> /SPAN>{/P> /SPAN>c.CategoryID,/P> /SPAN>c.CategoryName/P> /SPAN>};/P> Its Lambda equivalent would be /P> var t = BlogBLL.Categories.Where(c => c.CategoryID <= 5)/P> /SPAN>.Select(c => new {c.CategoryID, c.CategoryName});Hope this makes it easy to understand how much of help Lambda expression can be when writing the LINQ expressions.Vikram/SPAN>
Previous LINQ query (Select some fields from a given class using the anonymous types)/P>
/SPAN>var t = from c in BlogBLL.Categories/P> /SPAN>select new /P> /SPAN>{/P> /SPAN>c.CategoryID,/P> /SPAN>c.CategoryName/P> /SPAN> /SPAN>};/P> Its Lambda equivalent would be /P> var t = BlogBLL.Categories.Select(c => new {c.CategoryID, c.CategoryName});/P> LINQ query to select some fields from the category class where the categoryId is greater than equal to 5/P> var t = from c in BlogBLL.Categories/P> /SPAN>where c.CategoryID /SPAN><= 5/P> /SPAN>select new /P> /SPAN>{/P> /SPAN>c.CategoryID,/P> /SPAN>c.CategoryName/P> /SPAN>};/P> Its Lambda equivalent would be /P> var t = BlogBLL.Categories.Where(c => c.CategoryID <= 5)/P> /SPAN>.Select(c => new {c.CategoryID, c.CategoryName});Hope this makes it easy to understand how much of help Lambda expression can be when writing the LINQ expressions.Vikram/SPAN>
/SPAN>select new /P> /SPAN>{/P> /SPAN>c.CategoryID,/P> /SPAN>c.CategoryName/P> /SPAN> /SPAN>};/P> Its Lambda equivalent would be /P> var t = BlogBLL.Categories.Select(c => new {c.CategoryID, c.CategoryName});/P> LINQ query to select some fields from the category class where the categoryId is greater than equal to 5/P> var t = from c in BlogBLL.Categories/P> /SPAN>where c.CategoryID /SPAN><= 5/P> /SPAN>select new /P> /SPAN>{/P> /SPAN>c.CategoryID,/P> /SPAN>c.CategoryName/P> /SPAN>};/P> Its Lambda equivalent would be /P> var t = BlogBLL.Categories.Where(c => c.CategoryID <= 5)/P> /SPAN>.Select(c => new {c.CategoryID, c.CategoryName});Hope this makes it easy to understand how much of help Lambda expression can be when writing the LINQ expressions.Vikram/SPAN>
/SPAN>{/P> /SPAN>c.CategoryID,/P> /SPAN>c.CategoryName/P> /SPAN> /SPAN>};/P> Its Lambda equivalent would be /P> var t = BlogBLL.Categories.Select(c => new {c.CategoryID, c.CategoryName});/P> LINQ query to select some fields from the category class where the categoryId is greater than equal to 5/P> var t = from c in BlogBLL.Categories/P> /SPAN>where c.CategoryID /SPAN><= 5/P> /SPAN>select new /P> /SPAN>{/P> /SPAN>c.CategoryID,/P> /SPAN>c.CategoryName/P> /SPAN>};/P> Its Lambda equivalent would be /P> var t = BlogBLL.Categories.Where(c => c.CategoryID <= 5)/P> /SPAN>.Select(c => new {c.CategoryID, c.CategoryName});Hope this makes it easy to understand how much of help Lambda expression can be when writing the LINQ expressions.Vikram/SPAN>
/SPAN>c.CategoryID,/P> /SPAN>c.CategoryName/P> /SPAN> /SPAN>};/P> Its Lambda equivalent would be /P> var t = BlogBLL.Categories.Select(c => new {c.CategoryID, c.CategoryName});/P> LINQ query to select some fields from the category class where the categoryId is greater than equal to 5/P> var t = from c in BlogBLL.Categories/P> /SPAN>where c.CategoryID /SPAN><= 5/P> /SPAN>select new /P> /SPAN>{/P> /SPAN>c.CategoryID,/P> /SPAN>c.CategoryName/P> /SPAN>};/P> Its Lambda equivalent would be /P> var t = BlogBLL.Categories.Where(c => c.CategoryID <= 5)/P> /SPAN>.Select(c => new {c.CategoryID, c.CategoryName});Hope this makes it easy to understand how much of help Lambda expression can be when writing the LINQ expressions.Vikram/SPAN>
/SPAN>c.CategoryName/P> /SPAN> /SPAN>};/P> Its Lambda equivalent would be /P> var t = BlogBLL.Categories.Select(c => new {c.CategoryID, c.CategoryName});/P> LINQ query to select some fields from the category class where the categoryId is greater than equal to 5/P> var t = from c in BlogBLL.Categories/P> /SPAN>where c.CategoryID /SPAN><= 5/P> /SPAN>select new /P> /SPAN>{/P> /SPAN>c.CategoryID,/P> /SPAN>c.CategoryName/P> /SPAN>};/P> Its Lambda equivalent would be /P> var t = BlogBLL.Categories.Where(c => c.CategoryID <= 5)/P> /SPAN>.Select(c => new {c.CategoryID, c.CategoryName});Hope this makes it easy to understand how much of help Lambda expression can be when writing the LINQ expressions.Vikram/SPAN>
/SPAN> /SPAN>};/P> Its Lambda equivalent would be /P> var t = BlogBLL.Categories.Select(c => new {c.CategoryID, c.CategoryName});/P> LINQ query to select some fields from the category class where the categoryId is greater than equal to 5/P> var t = from c in BlogBLL.Categories/P> /SPAN>where c.CategoryID /SPAN><= 5/P> /SPAN>select new /P> /SPAN>{/P> /SPAN>c.CategoryID,/P> /SPAN>c.CategoryName/P> /SPAN>};/P> Its Lambda equivalent would be /P> var t = BlogBLL.Categories.Where(c => c.CategoryID <= 5)/P> /SPAN>.Select(c => new {c.CategoryID, c.CategoryName});Hope this makes it easy to understand how much of help Lambda expression can be when writing the LINQ expressions.Vikram/SPAN>
Its Lambda equivalent would be /P>
var t = BlogBLL.Categories.Select(c => new {c.CategoryID, c.CategoryName});/P>
LINQ query to select some fields from the category class where the categoryId is greater than equal to 5/P>
var t = from c in BlogBLL.Categories/P>
/SPAN>where c.CategoryID /SPAN><= 5/P> /SPAN>select new /P> /SPAN>{/P> /SPAN>c.CategoryID,/P> /SPAN>c.CategoryName/P> /SPAN>};/P> Its Lambda equivalent would be /P> var t = BlogBLL.Categories.Where(c => c.CategoryID <= 5)/P> /SPAN>.Select(c => new {c.CategoryID, c.CategoryName});Hope this makes it easy to understand how much of help Lambda expression can be when writing the LINQ expressions.Vikram/SPAN>
/SPAN>select new /P> /SPAN>{/P> /SPAN>c.CategoryID,/P> /SPAN>c.CategoryName/P> /SPAN>};/P> Its Lambda equivalent would be /P> var t = BlogBLL.Categories.Where(c => c.CategoryID <= 5)/P> /SPAN>.Select(c => new {c.CategoryID, c.CategoryName});Hope this makes it easy to understand how much of help Lambda expression can be when writing the LINQ expressions.Vikram/SPAN>
/SPAN>{/P> /SPAN>c.CategoryID,/P> /SPAN>c.CategoryName/P> /SPAN>};/P> Its Lambda equivalent would be /P> var t = BlogBLL.Categories.Where(c => c.CategoryID <= 5)/P> /SPAN>.Select(c => new {c.CategoryID, c.CategoryName});Hope this makes it easy to understand how much of help Lambda expression can be when writing the LINQ expressions.Vikram/SPAN>
/SPAN>c.CategoryID,/P> /SPAN>c.CategoryName/P> /SPAN>};/P> Its Lambda equivalent would be /P> var t = BlogBLL.Categories.Where(c => c.CategoryID <= 5)/P> /SPAN>.Select(c => new {c.CategoryID, c.CategoryName});Hope this makes it easy to understand how much of help Lambda expression can be when writing the LINQ expressions.Vikram/SPAN>
/SPAN>c.CategoryName/P> /SPAN>};/P> Its Lambda equivalent would be /P> var t = BlogBLL.Categories.Where(c => c.CategoryID <= 5)/P> /SPAN>.Select(c => new {c.CategoryID, c.CategoryName});Hope this makes it easy to understand how much of help Lambda expression can be when writing the LINQ expressions.Vikram/SPAN>
/SPAN>};/P> Its Lambda equivalent would be /P> var t = BlogBLL.Categories.Where(c => c.CategoryID <= 5)/P> /SPAN>.Select(c => new {c.CategoryID, c.CategoryName});Hope this makes it easy to understand how much of help Lambda expression can be when writing the LINQ expressions.Vikram/SPAN>
var t = BlogBLL.Categories.Where(c => c.CategoryID <= 5)/P> /SPAN>.Select(c => new {c.CategoryID, c.CategoryName});Hope this makes it easy to understand how much of help Lambda expression can be when writing the LINQ expressions.Vikram/SPAN>
Hi, I would like to if we could update two or more tables simultaneously using lambada expression in LINQ TO SQL (C#.Net) /p>