nHibernate Criteria API投影 [英] nHibernate Criteria API Projections

查看:102
本文介绍了nHibernate Criteria 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; }
}

我正在尝试使用Criteria API这样查询它.

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

当我运行此查询时,Customer对象的Addresses属性为null.无论如何,是否要为此List属性添加投影?

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?

推荐答案

代码似乎不错.因此问题可能出在Addresses属性的映射中.

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

这篇关于nHibernate Criteria API投影的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆