The usage of Find and Query method

Jul 4, 2014 at 7:11 AM
Hi there,
Thanks Le Long
seems the package has most of the necessities.
I tried to learn and use your library, but have some difficulties with the two mentioned methods and the path I should take for them,
In summary I have 3 related questions, which they could be handy for someone like me,
thanks for any help

1. The Find method :
it uses params to look more dynamic I think, but couldn't find enough info how to use it,

for example I wrote a sample derived service for a type "Magic"
MagicService : Service<Magic>
now we want to have a specific method
FindByTitle(string stTitle)
{
     return Find(.....); 
}
how to achieve this the best way.

2. The Query method
you said it's better to return Queryable than IEnumerable,
and most in the repository will return IQueryFluent() ,
which couldn't cast it to my need,
at last couldn't deal with the result and get something like FirstOrDefault or SingleOrDefault
out of it.
Magic mag = svc.Query().Include(m=> m.Timeout == 30).Select().FirstOrDefault();
3. a general SearchByTitle
How to put something like this within the Repository and your service,

I tried to define an interface ITitle ,
if (TEntity is ITitle) ...
but seems a bit more work it needs.

Thanks for any help, provided info and your great effort.
Coordinator
Jul 7, 2014 at 3:44 PM
  1. Please see: https://genericunitofworkandrepositories.codeplex.com/wikipage?title=Adding%20Custom%20Queries%20to%20Repository
  2. This is incorrect, we are not stating IQueryable is better than IEnumerable or vice versa, all teams have their preference of what a Repository should return. They will need to make this decision on what practice suits them best. By default the Repository returns IEnumerable with access to IQueryable to implement customer Repository methods. Teams can change the default behavior and return IQueryable if they choose, this takes two changes, one in IRepository and the other in Repository.
  3. I'm not sure what your trying to accomplish here, again to add custom Repository methods and expose them through the IService, Service, please see Please see: https://genericunitofworkandrepositories.codeplex.com/wikipage?title=Adding%20Custom%20Queries%20to%20Repository.
Marked as answer by lelong37 on 7/7/2014 at 8:44 AM