您好,欢迎来到微智科技网。
搜索
您的当前位置:首页NHibernate 对分组聚合支持的不好

NHibernate 对分组聚合支持的不好

来源:微智科技网

Hibernate 对分组聚合支持的不好,例如下面的代码:

var query = from raqi in session.Query()
   group raqi by raqi.SpaceKey
   into g
   select new {
      g.Key,
      Count = g.Count(r => r.Raqi > 1)
   };

这样的查寻生成的Sql如下,很明显是错误的,

    select
        factstatra0_.[SpaceKey] as col_0_0_,
        cast(count(*) as INT) as col_1_0_ 
    from
        [dbo].[FactStatRaqi] factstatra0_ 
    group by
        factstatra0_.[SpaceKey]

LinqToSql可以生成正确的sql

-- Region Parameters
DECLARE @p0 Float SET @p0 = 1
-- EndRegion
SELECT [t1].[SpaceKey] AS [Key], (
    SELECT COUNT(*)
    FROM [FactStatRaqi] AS [t2]
    WHERE ([t2].[RAQI] > @p0) AND ([t1].[SpaceKey] = [t2].[SpaceKey])
    ) AS [Count]
FROM (
    SELECT [t0].[SpaceKey]
    FROM [FactStatRaqi] AS [t0]
    GROUP BY [t0].[SpaceKey]
    ) AS [t1]

看来,NH的Linq查寻还有很长的路要走。

因篇幅问题不能全部显示,请点此查看更多更全内容

Copyright © 2019- 7swz.com 版权所有 赣ICP备2024042798号-8

违法及侵权请联系:TEL:199 18 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务