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

397 views Asked by At

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?

1

There are 1 answers

1
Rippo On BEST ANSWER

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