How to transform SQL query in DTO with nullable properties?

Viewed 2518

Having a DTO like this:

public class CustomerDTO
{
     public int Id{get; set;}
     public int? Reference {get; set;}
}

How can I get it from

var q =_session.CreateSQLQuery("SELECT Id, Reference FROM customers")

If I use

q.SetResultTransformer(Transformers.AliasToBean<CustomerDTO>)

I get the following exception:

NHibernate.PropertyAccessException : The type System.Int32 can not be assigned to a property of type System.Nullable`1[System.Int32] setter of Customer.Reference

2 Answers
Related