代码之家  ›  专栏  ›  技术社区  ›  Craig

NHibernate标准API预测

  •  0
  • Craig  · 技术社区  · 15 年前

    我有一个这样的实体

    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属性为空。是否仍要为此列表属性添加投影?

    1 回复  |  直到 11 年前
        1
  •  0
  •   Fitzchak Yitzchaki    14 年前

    代码看起来不错。所以问题可以在地址属性的映射中。