Skip to main content

Posts

Showing posts with the label Linq Order by Descending Query

LINQ Architecture in ASP .Net C#

The LINQ has a 3 layered Architecture. In the upper layer consists of the language extensions and the bottom layer consists of data sources that are typically objects implementing IEnumerable <T> or IQueryable <T> generic interfaces. The LINQ contain some major components, 1.       LINQ to Objects. 2.       LINQ to ADO.NET, which includes. 3.       LINQ to SQL (formerly called DLinq). 4.       LINQ to DataSet (formerly called LINQ over DataSet). 5.       LINQ to Entities. 6.       LINQ to XML (formerly called XLinq). The LINQ Architecture show as below,

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 “ t...

LINQ Queries Examples Using Query Method and Query Syntax

Basically, the LINQ queries using query syntax and method syntax. The method syntax called Lambda Expressions. The LINQ query syntax is close to native language and it is simple and easy to read. The method syntax is powerful but it is shorter and suitable tool. They compile the same and both are equivalent. 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. You can see the LINQ Query in the below pic, So, here I am trying to explain gather T-SQL queries along with their equivalent LINQ queries in the both method and query syntax. 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 along with their equivalent LINQ queri...

LINQ Tutorial for beginners in ASP.Net C# Examples

What, Why and How LINQ? What is LINQ? Why LINQ? What are LINQ Query and Method Syntax? What is Lambda expression? LINQ Architecture In ASP.Net? LINQ Advantages and Disadvantages? What is LINQ API? Understanding Var and IEnumerablewith LINQ IEnumerable Vs. IList IEnumerable Vs. IQueryable LINQ - Query Operators Where OfType OrderBy and OrderByDescending ThenBy and ThenByDescending Select All and Any Contains Aggregate Average GroupBy ToLookup Join GroupJoin Sum Max ElementAt and ElementAtOrDefault First and FirstOrDefault ...

Linq Order by Descending Query

Hello everyone, I am going to share the query for Order by Descending in Linq to SQL. The  query detail as given below. /// <summary> /// This method is used to get cart using OrderByDescending. /// </summary> public List < Cart > MyCarts( string EmailID, long CompanyID, long TenantID) {            return base .Context.Carts.Where(x => x.UserEmailID == EmailID && x.CompanyID == CompanyID && x.TenantID == TenantID && x.IsDeleted == false ). OrderByDescending (x=>x.ManageShoppingCartID).ToList();  }                                               OR var query = base .Context.Carts.OrderBy(x => x.PlaneName).ThenBy(x => x.DeviceName).ThenByDescending(x => x.CartID).ThenBy(x => x.Quantity).ToList(); ...