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.
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
Post a Comment