"Incorrect" sql is generated by nhibernate (sql that does not work in sql server 2005)
ICriteria criteria1 = NHibSessionManager.Instance.GetSession().CreateCriteria(typeof(Category));
criteria1.Add(Expression.IsNull("ParentId"));
criteria1.SetFirstResult(0);
criteria1.SetMaxResults(1);
Generates sql:
exec sp_executesql N'WITH query AS (SELECT TOP 1 ROW_NUMBER() OVER (ORDER BY this_.SortIndex desc) as __hibernate_row_nr__, this_.CategoryId as CategoryId20_0_,
this_.ApplicationId as Applicat2_20_0_, this_.ParentId as ParentId20_0_, this_.Name as Name20_0_, this_.Description as Descript5_20_0_, this_.Selectable as
Selectable20_0_, this_.SortIndex as SortIndex20_0_, this_.InsertStamp as InsertSt8_20_0_, this_.UpdateStamp as UpdateSt9_20_0_ FROM
CommunityFramework.dbo.cfCategory this_ WHERE this_.ParentId = @p0 ORDER BY this_.SortIndex desc) SELECT * FROM query WHERE __hibernate_row_nr__ > 0 ORDER BY
__hibernate_row_nr__',N'@p0 uniqueidentifier',@p0=NULL
The problem is that sql server does not work with ...WHERE this_.ParentId = @p0... ...N'@p0 uniqueidentifier',@p0=NULL
If I modify this sql in query analyzer to
exec sp_executesql N'WITH query AS (SELECT TOP 1 ROW_NUMBER() OVER (ORDER BY this_.SortIndex desc) as __hibernate_row_nr__, this_.CategoryId as CategoryId20_0_,
this_.ApplicationId as Applicat2_20_0_, this_.ParentId as ParentId20_0_, this_.Name as Name20_0_, this_.Description as Descript5_20_0_, this_.Selectable as
Selectable20_0_, this_.SortIndex as SortIndex20_0_, this_.InsertStamp as InsertSt8_20_0_, this_.UpdateStamp as UpdateSt9_20_0_ FROM
CommunityFramework.dbo.cfCategory this_ WHERE this_.ParentId IS NULL ORDER BY this_.SortIndex desc) SELECT * FROM query WHERE __hibernate_row_nr__ > 0 ORDER BY
__hibernate_row_nr__',N'@p0 uniqueidentifier',@p0=NULL
I get the row i asking for
Is this a bug in nhibernate or a limitation in SQL Server 2005
Hibernate version:1.2.0RC1
|