After upgrading ServiceStack.OrmLite from 5.9 to 5.11 we have noticed that some of ORM queries are producing invalid MS SQL queries.
The issue can be reproduced with the following tests:
using NUnit.Framework;
namespace ServiceStack.OrmLite.SqlServerTests.Issues
{
[TestFixture]
public class CountDistinctTests : OrmLiteTestBase
{
public class CountDistinctIssueTable
{
public long AutoId { get; set; }
}
[Test]
public void CountDistinctTest()
{
Execute(SqlServerDialect.Provider);
}
[Test]
public void CountDistinctTest2008()
{
Execute(SqlServer2008Dialect.Provider);
}
[Test]
public void CountDistinctTest2012()
{
Execute(SqlServer2012Dialect.Provider);
}
private void Execute(IOrmLiteDialectProvider dialectProvider)
{
using (var db = OpenDbConnection("Data Source=(localdb);Integrated Security=True;Initial Catalog=OrmTest", dialectProvider))
{
db.DropAndCreateTable<CountDistinctIssueTable>();
var query = db.From<CountDistinctIssueTable>();
query.Skip(0);
db.Scalar<long>(query.Select(x => Sql.CountDistinct(x.AutoId)));
}
}
}
}
SQL produced before (version 5.9 - SQL2008 dialect):
SELECT COUNT(DISTINCT "AutoId")
FROM "CountDistinctIssueTable"
SQL produced after (version 5.11 - SQL2012 dialect):
SELECT COUNT(DISTINCT "AutoId")
FROM "CountDistinctIssueTable" ORDER BY "CountDistinctIssueTable"."AutoId" OFFSET 0 ROWS
We believe this is a bug in a latest version of OrmLite. Can you please investigate this?