Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix SQL Server dialect paging bug (NH-3138)
The MsSql2005DialectQueryPager was found to be incorrectly identifying columns in the ORDER BY expression of a query that contains a function with parameters separated by commas (e.g. "ORDER BY COALESCE(param1, param2)"). Employed a regular expression for a more sophisticated method of identifying the columns.
- Loading branch information
1 parent
7a7e91f
commit 8d7b870
Showing
4 changed files
with
74 additions
and
2 deletions.
There are no files selected for viewing
65 changes: 65 additions & 0 deletions
65
src/NHibernate.Test/NHSpecificTest/NH3138/FixtureByCode.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
using System; | ||
using NHibernate.Mapping.ByCode; | ||
using NUnit.Framework; | ||
|
||
namespace NHibernate.Test.NHSpecificTest.NH3138 | ||
{ | ||
[TestFixture] | ||
public class FixtureByCode : TestCaseMappingByCode | ||
{ | ||
protected override bool AppliesTo(Dialect.Dialect dialect) | ||
{ | ||
return dialect is Dialect.MsSql2005Dialect; | ||
} | ||
|
||
protected override Cfg.MappingSchema.HbmMapping GetMappings() | ||
{ | ||
var mapper = new ModelMapper(); | ||
mapper.Class<Entity>(ca => | ||
{ | ||
ca.Lazy(false); | ||
ca.Id(x => x.Id, map => map.Generator(Generators.GuidComb)); | ||
ca.Property(x => x.EnglishName); | ||
ca.Property(x => x.GermanName); | ||
}); | ||
|
||
return mapper.CompileMappingForAllExplicitlyAddedEntities(); | ||
} | ||
|
||
[Test] | ||
public void PageQueryWithDistinctAndOrderByContainingFunctionWithCommaSeparatedParameters() | ||
{ | ||
using (var session = OpenSession()) | ||
{ | ||
Assert.DoesNotThrow(() => | ||
session | ||
.CreateQuery("select distinct e.Id, coalesce(e.EnglishName, e.GermanName) from Entity e order by coalesce(e.EnglishName, e.GermanName) asc") | ||
.SetFirstResult(10) | ||
.SetMaxResults(20) | ||
.List<Entity>()); | ||
} | ||
} | ||
|
||
[Test] | ||
[Ignore("Failing")] | ||
public void PageQueryWithDistinctAndOrderByContainingAliasedFunction() | ||
{ | ||
using (var session = OpenSession()) | ||
{ | ||
Assert.DoesNotThrow(() => | ||
session | ||
.CreateQuery("select distinct e.Id, coalesce(e.EnglishName, e.GermanName) as LocalizedName from Entity e order by LocalizedName asc") | ||
.SetFirstResult(10) | ||
.SetMaxResults(20) | ||
.List<Entity>()); | ||
} | ||
} | ||
} | ||
|
||
class Entity | ||
{ | ||
public Guid Id { get; set; } | ||
public string EnglishName { get; set; } | ||
public string GermanName { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters