Working with the Expression<Func<TEntity, bool>> "criteria" when using Linq-to-NH Where methods

34 views
Skip to first unread message

Nieve

unread,
Nov 15, 2009, 10:24:54 AM11/15/09
to altnetuk-discuss
Hello all,
I'm working on an app using linq-to-nhibernate and ASP.NET MVC.
We've just ran into our first user story of a search page and I was
wondering how to approach it. We basically get a ViewModel with the
users search criteria (which might be empty) and then need to call our
repository to use Session.Linq<T>.Where(expression);
What I'm trying to work out is whether to verify each and every time
whether the criteria isn't null or empty and then construct the
criteria (user => user.Surname == viewModel.Surname && user.Birthdate
== viewModel.Birthdate), use Repository methods per property that
return IQueryable (userRepository.GetBySurname,
userRepository.GetByBirthdate etc'), or having a method taking in
Func<T, object> (for each property that could be searched) and the
ViewModel and would return the Expression<Func<T, bool>> for each
property that is not empty? Hope this makes sense. How do you go about
doing this?

Would appreciate any feedback :)
Reply all
Reply to author
Forward
0 new messages