locked
What's the difference between Enumerable and Queryable RRS feed

  • Question

  • User264732274 posted

    please explain with example the difference between Enumerable and Queryable. thanks

    Thursday, September 8, 2016 2:58 PM

Answers

  • User765422875 posted

    In technical terms the main difference is that the LINQ operators for IQueryable<T> take Expression objects instead of delegates. This means the custom query logic it receives is in the form of an expression tree instead of a delegate to a method.

    Simply put:

    IEnumerable<T>

    • good for working with sequences that are iterated in-memory
    • allows you to go from one element of your collection over to the next

    IQueryable<T>

    • allows for out of memory things like a remote data source, such as a database or web service.

    http://www.dotnettricks.com/learn/linq/ienumerable-vs-iqueryable

    http://haroldrv.com/2015/02/what-is-the-difference-between-ienumerable-and-iqueryable/

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, September 8, 2016 5:31 PM
  • User347430248 posted

    Hi Sudip_inn,

    Below lists the differences between them based on their properties :

      IEnumerable  IQueryable
    Namespace System.Collections Namespace System.Linq Namespace
    Derives from No base interface Derives from IEnumerable
    Deferred Execution Supported Supported
    Lazy Loading Not Supported Supported
    How does it work While querying data from database, IEnumerable execute select query on server side, load data in-memory on client side and then filter data. Hence does more work and becomes slow. While querying data from database, IQueryable execute select query on server side with all filters. Hence does less work and becomes fast.
    Suitable for LINQ to Object and LINQ to XML queries. LINQ to SQL queries.
    Custom Query Doesn’t supports. Supports using CreateQuery and Execute methods.
    Extension mehtod parameter Extension methods supported in IEnumerable takes functional objects. Extension methods supported in IEnumerable takes expression objects i.e. expression tree.
    When to use when querying data from in-memory collections like List, Array etc. when querying data from out-memory (like remote database, service) collections.
    Best Uses In-memory traversal Paging

    For more information regarding difference between Enumerable and Queryable visit the links mentioned below.

    Understanding IEnumerable  and IQueryable in C#

    IEnumerable vs IQueryable in LINQ

    IEnumerable  Vs IQueryable

    Regards

    Deepak

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, September 9, 2016 12:26 AM

All replies

  • User765422875 posted

    In technical terms the main difference is that the LINQ operators for IQueryable<T> take Expression objects instead of delegates. This means the custom query logic it receives is in the form of an expression tree instead of a delegate to a method.

    Simply put:

    IEnumerable<T>

    • good for working with sequences that are iterated in-memory
    • allows you to go from one element of your collection over to the next

    IQueryable<T>

    • allows for out of memory things like a remote data source, such as a database or web service.

    http://www.dotnettricks.com/learn/linq/ienumerable-vs-iqueryable

    http://haroldrv.com/2015/02/what-is-the-difference-between-ienumerable-and-iqueryable/

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, September 8, 2016 5:31 PM
  • User347430248 posted

    Hi Sudip_inn,

    Below lists the differences between them based on their properties :

      IEnumerable  IQueryable
    Namespace System.Collections Namespace System.Linq Namespace
    Derives from No base interface Derives from IEnumerable
    Deferred Execution Supported Supported
    Lazy Loading Not Supported Supported
    How does it work While querying data from database, IEnumerable execute select query on server side, load data in-memory on client side and then filter data. Hence does more work and becomes slow. While querying data from database, IQueryable execute select query on server side with all filters. Hence does less work and becomes fast.
    Suitable for LINQ to Object and LINQ to XML queries. LINQ to SQL queries.
    Custom Query Doesn’t supports. Supports using CreateQuery and Execute methods.
    Extension mehtod parameter Extension methods supported in IEnumerable takes functional objects. Extension methods supported in IEnumerable takes expression objects i.e. expression tree.
    When to use when querying data from in-memory collections like List, Array etc. when querying data from out-memory (like remote database, service) collections.
    Best Uses In-memory traversal Paging

    For more information regarding difference between Enumerable and Queryable visit the links mentioned below.

    Understanding IEnumerable  and IQueryable in C#

    IEnumerable vs IQueryable in LINQ

    IEnumerable  Vs IQueryable

    Regards

    Deepak

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, September 9, 2016 12:26 AM