0

Link:

My repositories always returns IQueryable. The reason for this is that IQueryable is not dependent on EF whereas ObjectQuery is. So if I want my other layers to be persistance ignorant I don't want to introduce dependency on ObjectQuery.

a) I assume reason why repositories ( implemented using EF ) should return IQueryable instead of ObjectQuery is because other ORMs also use queries which return IQueryable, and by having repositories return IQueryable we can easily switch between EF and other ORMs, without having to change the public interface of a repository?

b) Besides EF and NHibernate, are there any other ORMs that also have queries which return IQueryable?

Thank you

Community
  • 1
  • 1
bckpwrld
  • 1,159
  • 1
  • 11
  • 23
  • a) Yes b) List.AsQueryable() can be used for testing purposes as well. There is also OData (but it only supports a tiny subset of IQueryable). – Aron Oct 07 '13 at 17:32
  • 1
    Wake-up call: http://blog.ploeh.dk/2012/03/26/IQueryableTisTightCoupling/ – Gert Arnold Oct 08 '13 at 12:19

1 Answers1

0

You should return IQueryable because that's the lingua franca of expression trees. If it's not IQueryable, it's either some other thing that understands Expression, or its some horrible custom language which gives you a greatly inferior programming experience to

var resultsINeed = getQueryable().Where(expression1).Select(expression2);

And if it understands the Expression example here, then it might as well just be IQueryable, because that's the whole point of IQueryable - to be that general abstraction, that everybody can reuse in their interfaces.

Tim Lovell-Smith
  • 15,310
  • 14
  • 76
  • 93