nHibernate Criteria API Projections
- by Craig
I have an entity that is like this
public class Customer
{
public Customer() { Addresses = new List<Address>(); }
public int CustomerId { get; set; }
public string Name { get; set; }
public IList<Address> Addresses { get; set; }
}
And I am trying to query it using the Criteria API like this.
ICriteria query = m_CustomerRepository.Query()
.CreateAlias("Address", "a", NHibernate.SqlCommand.JoinType.LeftOuterJoin);
var result = query
.SetProjection(Projections.Distinct(
Projections.ProjectionList()
.Add(Projections.Alias(Projections.Property("CustomerId"), "CustomerId"))
.Add(Projections.Alias(Projections.Property("Name"), "Name"))
.Add(Projections.Alias(Projections.Property("Addresses"), "Addresses"))
))
.SetResultTransformer(new AliasToBeanResultTransformer(typeof(Customer)))
.List<Customer>() as List<Customer>;
When I run this query the Addresses property of the Customer object is null. Is there anyway to add a projection for this List property?