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; }
}
我正在尝试使用像这样的 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 属性为 null。 是否有办法为此 List 属性添加投影?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
代码看起来不错。 因此问题可能出在 Addresses 属性的映射中。
The code seems to be good. So the problem can be in the mapping for the Addresses property.