Nick
Nick

Reputation: 1891

NHibernate variable limits with SQL 2000

I am trying to use the Take method in hibernate with SQL 2000. When doing so, it gives me the error:Dialect does not support variable limits.

In searching around I found a way to override the check for variable limit support and set my code up as follows:

        return Fluently.Configure()
                       .Database(PersistenceConfigurer("####"))
                       .Mappings(m => m.HbmMappings.AddFromAssembly(Assembly.Load("####")))
                       .Mappings(m => m.FluentMappings.AddFromAssembly(Assembly.Load("####")))
                       .CurrentSessionContext<WebSessionContext>()
                       .BuildSessionFactory();
    }

    private static IPersistenceConfigurer PersistenceConfigurer(string connection)
    {
        var provider = MsSqlConfiguration.MsSql2000.ConnectionString(connection);
        provider.Dialect<FixedDialect>();
        return provider;
    } 
}
public class FixedDialect : NHibernate.Dialect.MsSql2000Dialect
{
    public override bool SupportsVariableLimit
    {
        get
        {
            return true;
        }
    }
}

This seems to generate the correct syntax. It creates the statement

[ select top @p0 order0_.field1 as field1_, order0_.field2 as field2_ from db.table order0_ where order0_.field3=@p1 ]
  Name:p1 - Value:LY02  Name:p2 - Value:10

But it's not setting a value for @p0, so it kicks back Line 1: Incorrect syntax near '@p0'.

Is there anything I can do to fix this? Why doesn't this dialect support the top function?

Upvotes: 2

Views: 193

Answers (1)

Nick
Nick

Reputation: 1891

I simply needed to update NHibernate to the latest version. This issue does not exist in version 4.0.3.

Upvotes: 1

Related Questions