【问题标题】:LINQ To NHibernate ignores the 'Group by' clauseLINQ To NHibernate 忽略“分组依据”子句
【发布时间】:2011-08-05 22:33:18
【问题描述】:

我使用 NHibernate 3.2.0,我无法让 LINQ 提供程序为此语句生成正确的 SQL 查询:

var result = (from translation in session.Query<TmTranslation>()
              where translation.Id > 0
              group translation by translation.Language into grp
              select new { Lang = grp.Key.Code }).ToList();

生成的SQL是

select tmtranslat0_.id                        as id32_,
       tmtranslat0_.status                    as status32_,
       tmtranslat0_.text                      as text32_,
       tmtranslat0_.last_revision             as last4_32_,
       tmtranslat0_.fk_id_translation_unit    as fk5_32_,
       tmtranslat0_.fk_id_translator          as fk6_32_,
       tmtranslat0_.fk_id_last_modifier       as fk7_32_,
       tmtranslat0_.fk_id_last_match_category as fk8_32_,
       tmtranslat0_.fk_id_language            as fk9_32_
from   "TRANSLATION" tmtranslat0_
where  tmtranslat0_.id > 0

这当然会导致从数据库中加载所有实体并将结果集分组到内存中(结果本身是正确的)。

我想要这样的东西

select tmtranslat0_.fk_id_language
from   "TRANSLATION" tmtranslat0_
where  tmtranslat0_.id > 0
group by tmtranslat0_.fk_id_language

改为生成。

我错过了什么吗?

非常感谢。

【问题讨论】:

    标签: nhibernate linq-to-nhibernate


    【解决方案1】:

    我唯一能建议的是使用QueryOver API。

    【讨论】:

      猜你喜欢
      • 2013-07-11
      • 1970-01-01
      • 2020-12-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-08-05
      • 1970-01-01
      相关资源
      最近更新 更多