0
我試圖讓這個查詢沒有運氣的工作。我有一個人物對象,名字,姓氏,ID和其他不應該被返回的字段。該查詢應該只返回其完整名稱包含一些字符串值的人員。該查詢也用於分頁,所以我必須跳過記錄並記錄。NHibernate哪裏包含/ OrderBy /跳過/採取/選擇新實體
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();
@stuartd的地方/像不工作而選擇不工作。 – Jeff
「like」不工作的方式是什麼?記錄太多?太少了?如果「bob」是名字或姓氏的一部分,你會得到任何結果嗎? –
@GrantWinney System.InvalidOperationException:從範圍''引用類型'Person'的變量'person',但沒有定義 – Jeff