Domanda

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?

È stato utile?

Soluzione

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;}}
}
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top