Search code examples
linqlinq-to-objectslinq-query-syntax

Is LINQ-to-Object is a LINQ provider?


I have some confusion that, In Linq-to-Object we work in-memory data to execute LINQ query that is process by c# language.

When i write a Linq query that is execute base on in-memory data why we use provider (LINQ-to-Object)?


Solution

  • No, Linq to Object IS NOT A PROVIDER and it doesn't have to relay on any other intermediate provider to run query(linq to object).

    To understand it more clearly, we have to understand what provider actually is. Provider is basically the implementation that implements IQueryProvider and IQueryable interface and this mainly translates your linq query to SOMETHING that your provider understands. For example, when you go for LINQ to SQL queries your queries converted/translated into SQL, its get translated into SQL because your provider (in this case) only understands SQL.

    When you run query against In-Memory collection of data, C# don't have to translate your linq query to other query.

    As @Stilgar mention "Providers are used when the source is IQueryable". When you are working against In-Memory data, your source is basically IEnumerable.