I am building a repository and I've seen in many places 2 reasons not to expose IQueryable outside the repository.
1) The first is because different LINQ providers could behave differently, and this difference should be contained within the repository.
2) The second is to prevent service level developers from modifying the database query such that it accidentally causes performance issues.
I guess issue 2 can only be prevented by keeping all query logic within the repository and not allowing any form of external query building? But that does seem a bit impractical to me.
Issue 1 would seem to be resolved by using the Data Object Pattern.
e.g. public IEnumerable<T> FindBy(Query query)
My question is, why would I not just pass a lambda expression in, as that is provider independent, would appear to provide me with the same functionality as a query object, and the same level of separation?
e.g. public IEnumerable<T> FindBy(Expression<Func<T,bool>> predicate)
Is there any reason not to do this? Does it break some rules? Best-practises? that I should know about?