0
我有以下查询HNibernate:有助于避免N + 1查询
DetachedCriteria criteria = DetachedCriteria.For(typeof(Income))
.CreateAlias("Product", "p")
.SetProjection(
Projections.ProjectionList()
.Add(Projections.GroupProperty("Product"))
.Add(Projections.Sum("Quantity"))
);
其转换为SQL:
SELECT this_.Product_id as y0_,
sum(this_.Quantity) as y1_
FROM income this_
inner join products p1_
on this_.Product_id = p1_.Id
GROUP BY this_.Product_id
我的域名:
class Product
{
IList<Income> Incomes {get;set;}
}
class Income
{
Product Product {get;set;}
}
迭代时返回的集合我对每个Product实体都有一个查询。 如何在一个查询中获取所有集合?
你可以尝试使用SetFetchMode属性吗? http://nhprof.com/Learn/Alerts/SelectNPlusOne – rebelliard 2010-09-16 13:01:30
已经尝试过 - SetFetchMode(“p”,FetchMode.Join)没有效果 – kilonet 2010-09-16 13:18:33