Skip to content

Instantly share code, notes, and snippets.

@carcer
Forked from johnnonolan/nh.cs
Created January 5, 2012 11:28
Show Gist options
  • Save carcer/1564876 to your computer and use it in GitHub Desktop.
Save carcer/1564876 to your computer and use it in GitHub Desktop.
nh headache
static ICriterion BuildCriteria(params MatchableClientParams[] clientParams)
{
var result = Restrictions.Disjunction();
foreach (var parameters in clientParams)
{
var parameters1 = parameters;
var criteria = parameters1.BuildCriteria();
result.Add(criteria);
}
return result;
}
internal class MatchableClientParams
{
// doing it this way sorts the responsibilities a little and adds a little more extensibility. Because the MatchableClientParams is responsible for creating the ICriterion, you can subclass it to change behaviours without modifying any other code
public ICriterion BuildCriteria()
{
return Expression.Sql(string.Format("'{0}' like '%' + {1} + '%'", "SomeTextWithLastNameIn", "Name");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment