开发者

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?

PS. Version of Nhibernate is 1.2.1.400.


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)
)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜