[英]nHibernate Linq Projection
I am using the version 1.0 release of Linq for nHibernate. 我正在使用Linq的1.0版发行版用于nHibernate。 When I run the following linq statements I receive the error 当我运行以下linq语句时,出现错误
not a single-length projection: Surname 不是单一长度的投影:姓
I can find very few references to this on the web and looking into the source it says it should never occur! 我在网上找不到很少的参考资料,并从中发现它永远都不会发生的来源! ClientID is a Int type and Surname is a string. ClientID是一个Int类型,而Surname是一个字符串。 When I comment out all the string fields in the projection and just leave ClientID it runs ok, but as soon as I add surname back it errors. 当我注释掉投影中的所有字符串字段并仅保留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);
AFAIK, subqueries in select clauses aren't supported in LINQ to nHibernate 1.0. AFAIK,nHibernate 1.0的LINQ 不支持 select子句中的子查询。
This may be source of your problem. 这可能是您问题的根源。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.