C# ICriteria。添加like或
我有以下代码:C# ICriteria。添加like或,c#,nhibernate,C#,Nhibernate,我有以下代码: foreach (CheckedListBoxItem item in cbAttributes.Items) { if (item.CheckState == CheckState.Checked) { if ((string)item.Value == "Category" || (string)item.Value == "Kgs" || (string)item.Value == "Mks" |
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 + "%"));
}
}
}
循环后的条件如下所示:
C.Name like %text% AND K.Name like %text%
问题是我需要或
而不是和
。我该怎么做?注:Nhibernate的版本为1.2.1.400
Expression.Or(Expression.Like("param", param), Expression.Like("param", param))
如果在或语句中需要多于2个表达式,请选中(使用析取)
更新
此处描述:
“非常老”?你能告诉我们你正在使用的NHibernate的实际版本吗?
.Add(
Expression.Disjunction()
.Add(criteria)
.Add(other_criteria)
)