0

我有一个像这样的实体

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

我正在尝试使用像这样的 Criteria 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 属性为空。无论如何要为这个 List 属性添加一个投影?

4

1 回答 1

0

代码似乎很好。所以问题可能出在 Addresses 属性的映射中。

于 2010-02-14T08:10:30.150 回答