开发者

NHibernate 3 throwing NotSupportedException with SQL Compact 4.0 and FirstOrDefault()

I have a fairly simple piece of code that retrieves an object from the DB. This seems to work fine with SQL Server 2008, but blows up with SQL Server Compact. SQL Server CE supports TOP() - is this just a bug in NHibernate 3?

Code:

public override Profile GetProfileByName(string name)
{
    using (var tc = TC)
    {
        var query = from profiles in tc.Session.Query<Profile>()
                    where profiles.Name == name
                    select profiles;
        Profile profile = query.FirstOrDefault();
        tc.Commit();
        return profile;
    }
}

NHibernate Config:

<property name="dialect">NHibernate.Dialect.MsSqlCeDialect</property>
<property name="connection.driver_class">NHibernate.Driver.SqlServerCeDriver</property>
开发者_开发技巧

Exception:

System.NotSupportedException occurred
  Message=Dialect does not support limits.
  Source=NHibernate
  StackTrace:
       at NHibernate.Dialect.Dialect.GetLimitString(SqlString queryString, Nullable`1 offset, Nullable`1 limit, Parameter offsetParameter, Parameter limitParameter)
  InnerException: 


You are using the wrong dialect. Use MsSqlCe40Dialect.


For me MsSqlCe40Dialect is not working, i had to override SupportsVariableLimit in a custom dialect to get paging work.

public class MyDialect : MsSqlCe40Dialect
{
    public override bool SupportsVariableLimit
    {
        get
        {
            return true; 
        }
    }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜