2009-06-24 94 views
0

我就是這個樣子NHibernate的標準API預測

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; } 
} 

的實體,我試圖使用標準的API像這樣進行查詢。

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>; 

當我運行此查詢時,Customer對象的Addresses屬性爲null。無論如何要爲此List屬性添加投影嗎?

回答

0

該代碼似乎很好。所以這個問題可以在Addresses屬性的映射中。