IQueryable or IEnumerable as returns from Repositories
-
Hi all, Repository[^] pattern with Unit of Work[^] and Dependency Injection, seem to be a universaly accepted solution for ASP.NET + EF applications. There are still some minor questions that I would like to ask here. Consider the following method from a generic
IRepository
interface:public IQueryable Get() where T : class
{
return Set();
}I wonder, is it a good practice in reveling
IQueryable
interface to the callers. This means that the calling method can add filters/paggin/sorting, but at the same time the repository itself becomes not unit testable (you cant rely anymore on what the repository will actually return). The caller can even add a non-translatable predicate that will break at runtime. So, is it a good practice in hidingIQueryable
interface from the caller, and definingIEnumerable
interface instead? Also, I wonder how do you perform integration tests on repositories? Do you useSQL CE4
, fullSQL Server
, or just Fake objects onDbContext
? Appreciate your response, With regards -
Hi all, Repository[^] pattern with Unit of Work[^] and Dependency Injection, seem to be a universaly accepted solution for ASP.NET + EF applications. There are still some minor questions that I would like to ask here. Consider the following method from a generic
IRepository
interface:public IQueryable Get() where T : class
{
return Set();
}I wonder, is it a good practice in reveling
IQueryable
interface to the callers. This means that the calling method can add filters/paggin/sorting, but at the same time the repository itself becomes not unit testable (you cant rely anymore on what the repository will actually return). The caller can even add a non-translatable predicate that will break at runtime. So, is it a good practice in hidingIQueryable
interface from the caller, and definingIEnumerable
interface instead? Also, I wonder how do you perform integration tests on repositories? Do you useSQL CE4
, fullSQL Server
, or just Fake objects onDbContext
? Appreciate your response, With regardsI have no idea, but... Did you forget to encode your
<
and>
? He's fixed it.