linq (to nHibernate): 'like in' operator

前端 未结 3 1916
抹茶落季
抹茶落季 2021-01-22 16:46

Hi
Given a list of strings I want to retrieve all items whose names contain one of the given strings.
for example- given {\"foo\", \"kuku\"} I want to retrieve the emplo

3条回答
  •  生来不讨喜
    2021-01-22 16:59

    i used the following coding styles

    QueryOver

    IQueryOver rowCount = Session.QueryOver().ToRowCountQuery();
    
                        IQueryOver result = this.Session.QueryOver()
                         .Where(p => (p.FullNameEn.IsLike("%" + criteria.Keyword.Replace(" ", "%") + "%"))
                             || (p.FullNameAr.IsLike("%" + criteria.Keyword.Replace(" ", "%") + "%"))
                             || (p.IdentityNO == criteria.Keyword)
                             || (p.MobileNO == criteria.Keyword)
                             || (p.PatientID == patientIDKeyword)
                          )
                          .OrderBy(p => p.FullNameEn).Asc
                          .Take(criteria.PageSize)
                          .Skip((criteria.Page - 1) * criteria.PageSize);
    
    
                        totalCount = result.ToRowCountQuery().FutureValue().Value;
                        transaction.Commit();
                        return result.Future().ToList();
    

    LINQ

    var query = this.LINQ;
    query = query.Where(p => p.VendorNameAr.Contains(criteria.Keyword.Replace(" ", "%")) ||
                                                 p.VendorNameEN.Contains(criteria.Keyword.Replace(" ", "%")));
    return query.ToList();
    

提交回复
热议问题