views:

413

answers:

2

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?

A: 

The code seems to be good. So the problem can be in the mapping for the Addresses property.

Mendy
A: 

Im having the same problem. Any help would be appreciated.

John Peters