Created
January 4, 2012 16:22
-
-
Save johnnonolan/1560779 to your computer and use it in GitHub Desktop.
nh headache
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// I'm trying to dynamically build up criteria | |
ICriteria criteria = session.CreateCriteria<Client>().Add(BuildCriteria(clientParams)); | |
static ICriterion BuildCriteria(IEnumerable<MatchableClientParams> clientParams) | |
{ | |
var result = Restrictions.Disjunction(); | |
foreach (var parameters in clientParams) | |
{ | |
MatchableClientParams parameters1 = parameters; | |
result.Add(Restrictions.InsensitiveLike("LastName",clientParams.SomeTextWithLastNameIn,MatchMode.Anywhere)); | |
} | |
return result; | |
} | |
//This produces SELECT * FROM clients where LastName like '%'+@p1+'%' | |
//whereas I want | |
//SELECT * FROM clients where @p1 like '%'+LastName+'%' | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
//given
public class ClientParams
{
public string ClientImputText { get; set; }
public string DbField { get; set; }
}
//then
//does the job given
//if the db client table has an entry with "Griffiths" as the surname