我正在使用Linq for 1.0版本的nHibernate。我跑的时候 以下linq语句我收到错误
不是单一长度投影:姓氏
我可以在网上找到很少的引用并查看 来源说它永远不会发生! ClientID是Int类型和 姓氏是一个字符串。当我注释掉所有字符串字段时 投影,只需将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);