简体   繁体   English

NHibernate包含/订购/跳过/获取/选择到新实体的位置

[英]NHibernate Where Contains / OrderBy / Skip / Take / Select To New Entity

I'm trying to get this query to work with no luck. 我正在尝试使此查询无法正常运行。 I have a person object with a first name, last name, id and other fields that should not being returned. 我有一个带有名字,姓氏,ID和其他不应返回的字段的人员对象。 The query should return only people where their FULL NAME contains some string value. 该查询应仅返回其全名包含某些字符串值的人员。 The query is being used for pagination as well so I have to skip records and take records. 该查询也用于分页,因此我必须跳过记录并进行记录。

Session.QueryOver<Person>()
  // Only fetch records where full name matches some string (Not working)
  .WhereRestrictionOn(person => person.firstname + " " + person.lastname)
  .IsInsensitiveLike("%bob%")
  // Order by last then first name (Works if removing non-working parts)
  .OrderBy(person => person.lastname)
  .Asc
  .ThenBy(person => person.firstname)
  .Asc
  // Select to different object (Not working)
  .Select(person => new PersonDTO()
  {
    ID = person.ID,
    Name = person.firstname + " " + person.lastname
  })
  // Skip and take (Works if removing non-working parts)
  .Skip(50)
  .Take(50)
  .ToList();
var comboItem = new ComboBoxItem();

var result = Session.QueryOver<Person>()
  .WhereRestrictionOn(person => Projections.Concat(person.firstname, " ", person.lastname))
  .IsInsensitiveLike("%bob%")
  .OrderBy(person => person.lastname)
  .Asc
  .ThenBy(person => person.firstname)
  .Asc
  .SelectList(list => list
    .Select(person => person.ID).WithAlias(() => comboItem.id)
    .Select(person => Projections.Concat(person.firstname, " ", person.lastname)).WithAlias(() => comboItem.text)
  )
  .TransformUsing(Transformers.AliasToBean<ComboBoxItem>())
  .Skip(50)
  .Take(50)
  .List<ComboBoxItem>()
  .ToList();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM