views:

604

answers:

1

It makes sense to pass a filter object to the repository so it can limit what records return:

var myFilterObject = myFilterFactory.GetBlank();
myFilterObject.AddFilter( new Filter { "transmission", "eq", "Automatic"} );
var myCars = myRepository.GetCars(myfilterObject);

Key question: how would you implement paging and where? Any links on how to return a LazyList from a Repository as it would apply here? Would this be part of the filter object? Something like:

myFilterObject.AddFilter( new Filter { "StartAtRecord", "eq", "45"} );
myFilterObject.AddFilter( new Filter { "GetQuantity", "eq", "15"} );
var myCars = myRepository.GetCars(myfilterObject);

I assume the repository must implement filtering, otherwise you would get all records.

+4  A: 
Ryan
+1 for the thoughtful answer. As an addition, I would suggest actually returning IEnumerable even if you plan on using IQueryable, since not all things support IQueryable. If the object instance is an IQueryable, it'll still benefit from the late call to the db and so on, but you can switch to an impl. that doesn't direclty support IQueryable w/o having to change anything that depends on the interface.
Paul
Would you have to do a big case statement on the criteria to match the fields in the where clause?
Dr. Zim
@Dr. Zim: Actually there are several dynamic sorting implementations available online. Here's one that looks good. http://www.codeproject.com/KB/linq/Article.aspx?aid=27834 You can also do this using C#'s built in expression builders, but it's a bit more complicated. It looks like you already have filtering figured out.
Ryan