linq (to nHibernate): 'like in' operator

前端 未结 3 1921
抹茶落季
抹茶落季 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:53

    I Used the following code hope it helps;

       public IList GetCitiesLike(string text)
        {
            AutoCompleteDto autoCompleteDto = null;
    
            var cityList = UnitOfWork.CurrentSession.QueryOver()
                .Where(x => x.CityName.IsLike(text, MatchMode.Start))
                .SelectList(u => u
                                     .Select(x => x.Id).WithAlias(() => autoCompleteDto.Id)
                                     .Select(x => x.CityName).WithAlias(() => autoCompleteDto.Name)
                                     .Select(x => x.CityName).WithAlias(() => autoCompleteDto.Value))
                .TransformUsing(Transformers.AliasToBean())
                .List();
    
    
            return cityList;
        }
    

提交回复
热议问题