Skip to main content

Posts

Showing posts with the label simple count in Linq

"How to Use" IEnumerable and IQueryable [IEnumerable vs. IQueryable]

Both the IEnumerable and IQueryable interfaces are for . NET collections, so if you are new please see this article  and t he IQueryable interface inherits from IEnumerable interface, so whatever IEnumerable can do, IQueryable can also do. The IQueryable   interface   is the same as IEnumerable   interface    but it also provides additional functionality to implement custom querying with LINQ. Stayed Informed - IEnumerable vs. IList There are some differences over the interfaces IEnumerable and IQueryable as given below. IEnumerable :- The IEnumerable <T> interface exists in the namespace “ System.Collections ”. The IEnumerable <T> represents a forward only cursor of T . The IEnumerable <T> interface is fit for querying data from in memory collections like Array , List , and collations etc. While us querying data from the database. The IEnumerable executes SELECT Query on the server side, load list o...

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

What is LINQ? Why LINQ?

LINQ is stands for Language Integrated Query . LINQ is a Microsoft .NET Framework component and use for data querying . LINQ was released in Microsoft .NET Framework 3.5 on November 19, 2007. LINQ also defines a set of method names that is called standard query operators . LINQ a library for collection and iterator manipulation that makes extensive use of higher-order functions as arguments using  System.Linq . LINQ allows us to write queries directly in our database and these queries can be on relational databases, XML documents, objects , arrays and third-party data sources. LINQ also defines a new LINQ provider model that can take an expression tree and use it to run native queries against a data source outside of the CLR i.e. LINQ to SQL, LINQ to XML etc. LINQ is query syntax, not a language or an O/RM. You can build an O/RM on top of the syntax provided by LINQ . LINQ is kinds of universal query language. We can use LINQ queries in two ways, 1.  ...

How to do a simple count in Linq?

Query as given below for the same. var count = ( from x in yourtableView select x). Count ();                                     OR base .Context.yourtableView.Where(x => x.ID == ID).Count();