nhibernate或在sql语句中

fro*_*sty 0 nhibernate

我如何在nhibernate中获得相当于sql"或"的东西

我有以下方法.基本上我希望看​​看关键字是否在product.Name或Product.Description中找到.

   public ICollection<ProductCategory> FindByCompanyIdAndSearchAndPop(int companyId, string keyword)
    {
        var products = _session
            .CreateCriteria(typeof(ProductCategory))
            .CreateAlias("Product", "product", JoinType.InnerJoin)
            .Add(Restrictions.Eq("CompanyId", companyId))
            .Add(Restrictions.Eq("product.IsPopItem", true))
            .Add(Restrictions.Like("product.Name", keyword, MatchMode.Anywhere))
            .Add(Restrictions.Like("product.Description", keyword, MatchMode.Anywhere))
            .List<ProductCategory>();
        return products;
    }
Run Code Online (Sandbox Code Playgroud)

asg*_*las 5

||运营商目前超载的限制,所以你可以写:

.Add(
    Restrictions.Like("product.Name", keyword, MatchMode.Anywhere) ||
    Restrictions.Like("product.Description", keyword, MatchMode.Anywhere)))
Run Code Online (Sandbox Code Playgroud)