Comprehensive search with NHibernate

I am wondering what methods do you use for complex searches in NHibernate?

I use Ayende's

What's yours Thank you for your advice and answers.

+4
source share
3 answers

If we have a complex dynamic search, we will usually create a SearchParameter object and then pass it to a method that will build our criteria for us.

For example, if we were looking for a person, we could have a search object that looks like this:

public class PersonSearchParameters { public string FirstName {get; set;} public string LastName {get; set;} public ICriteria GetSearchCriteria() { DetachedCriteria query = DetachedCriteria.For(typeof (Person)); //Add query parameters Return query; } } 

Then for each type of search we can create a single criterion from the class or we will have a diverse search for parameter classes and their combination

+1
source

We use HQL, but we are still trying to wrap our heads with the Criteria API for complex queries. We need to manage a lot of duplication when using HQL.

+1
source

I use quite a lot of Ayende too jsut is a little more complicated, what do you want to do, what you cannot do with this?

We basically added that we have an interface where we define all the fields in which we want to perform a search, and call it when we are going to do a search, which means that we can easily change what we are looking for.

We also use Active Record in the project (at the top of Hibernate), and it's pretty cool, a lot of tasks are simplified, you lack of documents sometimes it hurts Cheer

+1
source

All Articles