nHibernate Linq Projection

Posted by Craig on Stack Overflow See other posts from Stack Overflow or by Craig
Published on 2009-08-20T22:35:28Z Indexed on 2010/05/12 19:04 UTC
Read the original article Hit count: 256

Filed under:
|
|
|

I am using the version 1.0 release of Linq for nHibernate. When I run the following linq statements I receive the error

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. 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.

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);

© Stack Overflow or respective owner

Related posts about nhibernate

Related posts about LINQ