locked
IEnumerable vs IQueryable , which one to use in SOA and non-SOA?

    Question

  • I am writing a Service Layer which has classes with methods returning lists of business objects, what should those methods' return types be ? IEnumerable or IQueryable and Why ?

    Thanks


    Fahad

    Friday, March 02, 2012 8:47 PM

Answers

  • On 3/2/2012 3:47 PM, Fahad349 wrote:
    > I am writing a Service Layer which has classes with methods returning
    > lists of business objects, what should those methods' return types be ?
    > IEnumerable or IQueryable and Why ?
    >
     
    It should return a List<T> which can be queried and enumerated.
     
     
    Friday, March 02, 2012 10:13 PM
  • Hi Fahad349,

    Welcome to MSDN Forum.

    The primary difference is that the extension methods defined for IQueryable<T> take Expression objects instead of Func objects, meaning the delegate it receives is an expression tree instead of a method to invoke. IEnumerable<T> is great for working with in-memory collections, but IQueryable<T> allows for a remote data source, like a database or web service.

    Here's an article I think can help you.

    http://odetocode.com/Articles/738.aspx

    Best Regards


    Allen Li [MSFT]
    MSDN Community Support | Feedback to us

    Monday, March 05, 2012 6:44 AM

All replies

  • On 3/2/2012 3:47 PM, Fahad349 wrote:
    > I am writing a Service Layer which has classes with methods returning
    > lists of business objects, what should those methods' return types be ?
    > IEnumerable or IQueryable and Why ?
    >
     
    It should return a List<T> which can be queried and enumerated.
     
     
    Friday, March 02, 2012 10:13 PM
  • Hi Fahad349,

    Welcome to MSDN Forum.

    The primary difference is that the extension methods defined for IQueryable<T> take Expression objects instead of Func objects, meaning the delegate it receives is an expression tree instead of a method to invoke. IEnumerable<T> is great for working with in-memory collections, but IQueryable<T> allows for a remote data source, like a database or web service.

    Here's an article I think can help you.

    http://odetocode.com/Articles/738.aspx

    Best Regards


    Allen Li [MSFT]
    MSDN Community Support | Feedback to us

    Monday, March 05, 2012 6:44 AM