似乎 NHibernate Linq 不理解分组的 .Where 方法条件。我得到以下代码:
var q = from o in session.Query<OrdreLinjeVerdier>()
where o.OrdreLinjeReserve > 0
group o by o.ProduktLager.ProduktLagerID into g
select new
{
ProduktLagerID = g.Key,
OrdreRes = g.Sum(x => x.OrdreLinjeReserve),
OrdreResUtenSpesial =
g.Where(x => x.LeveringsType.LeveringsTypeID == 1)
.Sum(x => (double?)x.OrdreLinjeReserve)
};
它就像这样进入数据库:
select ordrelinje0_.ProduktLagerID as col_0_0_,
cast(sum(ordrelinje0_.OrdreLinjeReserve) as DECIMAL(19,5)) as col_1_0_,
cast(sum(ordrelinje0_.OrdreLinjeReserve) as DOUBLE PRECISION) as col_2_0_
from OrdreLinjeVerdier ordrelinje0_
where ordrelinje0_.OrdreLinjeReserve>@p0
group by ordrelinje0_.ProduktLagerID;
@p0 = 0
所以基本上 g.Where 的条件对 SQL 查询没有影响。
看起来像错误还是我错过了什么?