Query (LINQ), is a component released within the .NET 3.5 Framework. It is one of the most powerful features of .NET 3.5. It serves the purpose of querying objects.
LINQ comprises a series of operators, which are used to query, filter and project data in arrays, enumerable classes, relational databases and XML. In order to query data, the data needs to be encapsulated as an object. In case the data source is not an object, it first needs to be converted to an object in order for LINQ to query it.
LINQ has its own Query Processing Engine. The information returned by a LINQ query is a collection of in-memory object which may be enumerated.
The LINQ concept treats the data source as an Object, rather than a Database. So we may say, its an object that is queried. LINQ may query any type of data source, like:
- LINQ querying SQL (MS SQL Server supported).
- LINQ querying Datasets (Querying is possible on Datasets and DataTables)
- LINQ querying ORM Solution
- LINQ querying Objects (In-memory data may be queried)
- LINQ querying XML (Querying is possible on XML data source
- LINQ supports querying to those objects that implement the IEnumerable Interface.
In the example code below, LINQ is being used to query a simple array containing integers:
- int[] values = new int[] {4,5,6,7};
-
- var output = from i in values where i < 4 orderby i select i;
-
- foreach(int j in values) Response.Write(j);