ICriteria.Add like OR
I have the following code:
foreach (CheckedListBoxItem item in cbAttributes.Items)
{
if (item.CheckState == CheckState.Checked)
{
if ((string)item.Value == "Category" || (string)item.Value == "Kgs" || (string)item.Value == "Mks" || (string)item.Value == "Author")
{
var alias = item.Value.ToString().Substring(0, 1);
criteria.CreateAlias(item.Value.ToString(), alias);
criteria.Add(Expression.Like(alias + ".Name", "%" + meTextToFind.Text + "%"));
开发者_Python百科 }
}
}
The criteria after loop looks like:
C.Name like %text% AND K.Name like %text%
The problem is that I need to OR
instead AND
. How can i do this?
Expression.Or(Expression.Like("param", param), Expression.Like("param", param))
If you need more then 2 expression in Or
statement, check this post (using Disjunction)
update
Described here: How to create OR statements for NHibernate?
.Add(
Expression.Disjunction()
.Add(criteria)
.Add(other_criteria)
)
精彩评论