1
我使用Linq for nHibernate的1.0版本。當我運行 以下LINQ語句我收到錯誤nHibernate Linq Projection
不是一個單一的長度投影:姓
我能找到的很少提到這個網站上,展望 源它說,這絕不應該發生! ClientID是一個Int類型, Surname是一個字符串。當我註釋掉 投影中的所有字符串字段並且僅留下ClientID時,它會正常運行,但只要我將 姓氏添加回給它即可。
var context = m_ClientRepository.Linq;
var result = (from client in context
from address in client.Addresses
from contact in client.Contacts
where client.Surname.StartsWith(surname)
&& client.GivenName.StartsWith(givenName)
&& contact.Value.StartsWith(phoneNumber)
group client by new { client.ClientID, client.Surname, client.GivenName } into clientGroup
select new ClientSearchDTO()
{
ClientID = clientGroup.Key.ClientID,
Surname = clientGroup.Key.Surname,
GivenName = clientGroup.Key.GivenName,
Address = clientGroup.Max(x => x.Addresses.FirstOrDefault().Address),
PhoneNumber = clientGroup.Max(x => x.Contacts.FirstOrDefault().Value)
})
.Skip(Paging.FirstRecord(pageNumber))
.Take(5);