I'm using NHibernate 2, and I'd like to be able to do the following:
I have many DAO types. They are all subclasses of BaseDAO, but they are not related in the NHibernate mappings at all. (These subclasses dot not all have common properties.)
I want to write a method that will search all of my DAO types and return a List<BaseDAO> containing all matches.
The method signature should look something like:
public IList<BaseDAO> GlobalSearch(string searchTerm, int startIdx, int maxRows);
The query needs to check searchTerm against all string properties of the domain types. We are currently doing this for one type at a time using a method that builds a Disjunction to search on all properties for a given type.
private Disjunction BuildDisjunction(string searchTerm, Type type)
I'd like to combine all of the disjunctions for all of my domain types and create one query that will return a list of the BaseDAO.
Here is what I have so far:
public IList<DomainBase> GlobalSearch(string searchTerm,
int startIndex, int maxRows)
{
ICriteria crit = GetCriteria<BaseDAO>();
foreach (Type t in GetAllDomainTypes())
{
Disjunction disj = BuildDisjunction(searchTerm, t);
// somehow use this disjunction
}
crit
.AddOrder(Order.Asc("DispName"))
.SetFirstResult(startIdx)
.SetMaxResults(maxRows);
return crit.List<BaseDAO>(); ;
}
Is this possible? How can I modify/complete the above method to achieve the functionality I need?