NHibernate 与 sql Server 2008 方言不支持变量限制

发布于 2024-12-15 04:26:21 字数 1356 浏览 3 评论 0原文

我在这里与一种奇怪的行为作斗争...... 使用 NHibernate 作为 ORM 和 MS SQL Server 2008 作为 DB 做一个 asp.net mvc3 应用程序,我遇到了这些例外:

System.NotSupportedException: Dialect does not support variable limits.

代码非常简单,一个经典的分页查询:

public IList<Agenzia> getAllAgenzie(int maximumRows, int startRowIndex)
    {           
        using (var session = PersistenceManager.Istance.GetSession()) {
            var result = (from agenzia in session.Query<Agenzia>()
                         select agenzia)
                         .Skip(startRowIndex)
                         .Take(maximumRows)
                         .ToList();
            return result;
        }
    }

这是 NHibernate 配置

<?xml version="1.0" encoding="utf-8" ?>
<!-- NHibernate Configuration -->
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
  <session-factory name="NHibernate.xlns">
    <property name="dialect">
      NHibernate.Dialect.MsSql2008Dialect
    </property>
    <property name="connection.driver_class">
      NHibernate.Driver.SqlClientDriver
    </property>
    <property name="show_sql">true</property>    
  </session-factory>
</hibernate-configuration>

知道它出了什么问题吗?我不敢相信 NHibernate 不支持这种简单的分页......

I'm fighting with a strange behavior here...
Doing an asp.net mvc3 application with NHibernate as ORM and MS SQL Server 2008 as the DB, I'm running into these exeption:

System.NotSupportedException: Dialect does not support variable limits.

The code is pretty simple, a classic pagination query:

public IList<Agenzia> getAllAgenzie(int maximumRows, int startRowIndex)
    {           
        using (var session = PersistenceManager.Istance.GetSession()) {
            var result = (from agenzia in session.Query<Agenzia>()
                         select agenzia)
                         .Skip(startRowIndex)
                         .Take(maximumRows)
                         .ToList();
            return result;
        }
    }

And here's the NHibernate configuration

<?xml version="1.0" encoding="utf-8" ?>
<!-- NHibernate Configuration -->
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
  <session-factory name="NHibernate.xlns">
    <property name="dialect">
      NHibernate.Dialect.MsSql2008Dialect
    </property>
    <property name="connection.driver_class">
      NHibernate.Driver.SqlClientDriver
    </property>
    <property name="show_sql">true</property>    
  </session-factory>
</hibernate-configuration>

Any idea what's wrong with it? I can't believe that NHibernate don't support this simple pagination...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

万劫不复 2024-12-22 04:26:21

您使用什么版本的 NHibernate? (最新的是 3.2)

它对我来说没有问题。

另外,这是多余的:

(from agenzia in session.Query<Agenzia>() select agenzia)

它相当于:

session.Query<Agenzia>()

What version of NHibernate are you using? (latest is 3.2)

It works without problems for me.

Also, this is redundant:

(from agenzia in session.Query<Agenzia>() select agenzia)

It's equivalent to:

session.Query<Agenzia>()
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文