nHibernate Criteria API Projections
Posted
by Craig
on Stack Overflow
See other posts from Stack Overflow
or by Craig
Published on 2009-06-24T02:04:54Z
Indexed on
2010/05/10
5:18 UTC
Read the original article
Hit count: 407
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?
© Stack Overflow or respective owner