Hello
I have a similar problem, and my solution is something like this:
I have a simple class with all the properties for the criteria. It has method, FillCriteria, which fills previously created criteria from the data in the class. For example:
Code:
class UserFilter
{
string Username = null;
int? MinAge = null ;
int? MaxAge = null ;
public void FillCriteria(ICriteria c)
{
if (string != null)
c.Add(Expression.Eq("Username",Username));
if (MinAge != null)
c.Add(Expression.Ge("Age", MinAge) ;
if (MaxAge != null)
c.Add(Expression.Lt("Age", MaxAge);
}
}
And, you can use it like this:
Code:
ICriteria c = CreateCriteria(typeof(User));
UserFilter uf = // load filter from DB, UI, or something
uf.FillCriteria(c) ;
c.List() ;
You can easily databind this UserFilter to the UI, serialize to XML (that's what I'm doing), save to the DB or something else.
HTH, Tom