Should I return IEnumerable or IQueryable from my DAL?

It depends on what behavior you want.

  • Returning an IList<T> tells the caller that they’ve received all of the data they’ve requested
  • Returning an IEnumerable<T> tells the caller that they’ll need to iterate over the result and it might be lazily loaded.
  • Returning an IQueryable<T> tells the caller that the result is backed by a Linq provider that can handle certain classes of queries, putting the burden on the caller to form a performant query.

While the latter gives the caller a lot of flexibility (assuming your repository fully supports it), it’s the hardest to test and, arguably, the least deterministic.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)