I know these questions have been asked before, I\'ll start by listing a few of them (the ones I\'ve read so far):
.Single()
).Compile()
on any lambdas, and uses LINQ-to-Objects instead. Note LINQ-to-Objects has more support than any other provider, so this won't be an issue - except that it means that any "mocks" using this approach don't really test your actual code at all and are largely pointless (IMO)Personally, I'd prefer well defined APIs here that take known parameters and return a loaded List
or IList
(or similar) of results; this gives you a testable/mockable API, and doesn't leave you at the mercy of deferred execution (closed connection hell, etc). It also means that any differences between providers is handled internally to the implementation of your data layer. It also makes a much closer fit for calling scenarios such as web-services, etc.
In short; given a choice between IEnumerable
and IQueryable
, I choose neither - opting instead to use IList
or List
. If I need additional filtering, then either: