Repository's GetMany and Get return all rows in database

Apr 26, 2011 at 4:49 AM
Edited Apr 26, 2011 at 5:17 AM

For example, change GetCategories() to do a search on name in the CategoryService, and then run the app and watch the generated SQL in SQL Profiler.
public IEnumerable<Category> GetCategories() {
  //var categories = _categoryRepository.GetAll();
  var categories = _categoryRepository.GetMany(p => p.Name == "abc");  // watch the SQL this generates, it doesn't have a where clause like you would expect.
  return categories;


I fixed it by changing these IRepository<T> functions:

//T Get(Func<T, bool> where);
T Get(Expression<Func<T, bool>> where);
//IEnumerable<T> GetMany(Func<T, bool> where);
IEnumerable<T> GetMany(Expression<Func<T, bool>> where);

I also made the same changes to RepositoryBase, and made RepositoryBase inherit IRepository.
Jun 29, 2011 at 4:37 AM

Could you please provided an example how you changed your repositorybase to inherit Irepository?

Maybe show an example how you would then change CategoryRepository to reflect those changes?


Thanks in advnace