Search code examples
nhibernatequeryovernhibernate-projections

NHibernate QueryOver Projection with combined property output..Is there any way?


I'm using NHibernate 3.2 and I'm trying to create a projection with two columns mapped to a string to build out full name.

var user = Session.QueryOver<Core.Domain.User>()
         .Select(u => u.FirstName + " " + u.LastName)
         .TransformUsing(Transformers.AliasToBean<UserDto>())
         .SingleOrDefault<UserDto>();

This is what I was hoping would work..but it doesn't. Does anyone know any tricks around this?


Solution

  • You can't! What I would do in this situation is to change my DTO e.g.

    public class UserDto {
      public virtual FirstName { get; set;}
      public virtual LastName { get; set;}
      public virtual FullName { get { return FirstName + " " + LastName;}}
    }