linq to sql - Should I return IEnumerable<T> or IQueryable<T> from my DAL? -


I know this can be the opinion, but I am looking for the best practices.

As I understand, IQueryable & lt; T & gt; implies IEnumerable & lt; T & gt; , so in my pulse, I currently have a legal sign such as:

  IEnumerable & lt; Products & gt; GetProducts (); IEnumerable & LT; Products & gt; GetProductsByCategory (Int cateogoryId); Product GetProduct (int productId);  

Do I get to IQueryable & lt; T & gt; should be used?

What are the pros and cons of the approach?

Note that I am planning to use the repository pattern so that I will get one such class:

  public-class product repository {DBDataContext db = New DBDataContext (& lt;! - - Connection string - & gt;); Public IEnumerable & lt; Products & gt; GetProductsNew (int daysOld) {returns db.GetProducts (). Where (P = & gt; P. addatetime & gt; date time.Now.AddDays (-daysOld)); }}  

Do I have my IEnumerable & lt; T & gt; to IQueryable & lt; T & gt; Change ?

It depends on what you want to behave.

  • A IILIT tells the returning caller that he has received all the data he has requested
  • < Li> A IEnumerable & lt; T & gt; Tells the caller that they will need to replay the result and it can be loaded load.
  • Create a IQueryable & lt; T & gt; The result of the returning collar is that it is supported by a link provider, which helps to handle some sections of the query by putting a load on the collar.
  • Later the caller has many flexibility (assuming that your repository fully supports it), it is most difficult to test and, of course, the minimum determinant .


    Comments

    Popular posts from this blog

    windows - Heroku throws SQLITE3 Read only exception -

    lex - Building a lexical Analyzer in Java -

    python - rename keys in a dictionary -