Linq API

Tram Ho

We can write queries for classes that implement via the IEnumerable <T> or Iqueryable <T> interfaces. The System.Linq namespace contains the following classes and interfaces that are required for LINQ queries.

LINQ queries use extension methods for classes that implement IEnumerable or IQueryable. IEnumerable and IQueryable are two static classes that contain extended methods for writing LINQ queries.

Enumeralbe:

The Enumerable class includes extension methods for classes that implement the IEnumerable <T> interface, for example, all the integrated collection classes implement the IEnumerable <T> interface and so we can write queries. LINQ to retrieve data from collections.

The following figure shows the extension methods included in the Enumerable class that can be used with generic collections in C # or VB.Net .

Below is a collection of all the extension methods available in the Enumerable class.

Queryable

The Queryable class includes extension methods for classes that implement the IQueryable <T> interface. The IQueryable <T> interface is used to provide query capabilities for a specific data source in which the data type is known. For example, the Entity Framework API implements the IQueryable <T> interface to support LINQ queries with baseline databases such as MS SQL Server.

In addition, there are APIs available to access third party data; For example, LINQ to Amazon provides the ability to use LINQ with Amazon web services to search for books and other items. This can be achieved by implementing the IQueryable interface for Amazon.

The following figure shows the extension methods available in the Query class that can be used with various original data providers or third parties.

The following figure shows the extension methods available in the Query class.

Share the news now

Source : Viblo