Skip to content
This repository was archived by the owner on Dec 24, 2022. It is now read-only.

Commit f075192

Browse files
committed
Add Count Distinct test
1 parent 11397c0 commit f075192

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

src/ServiceStack.OrmLite/OrmLiteReadCommandExtensions.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,8 @@ internal static List<T> SelectNonDefaults<T>(this IDbCommand dbCmd, string sql,
505505

506506
internal static IEnumerable<T> SelectLazy<T>(this IDbCommand dbCmd, string sql, IEnumerable<IDbDataParameter> sqlParams)
507507
{
508-
foreach (var p in dbCmd.SetParameters(sqlParams).SelectLazy<T>(sql)) yield return p;
508+
foreach (var p in dbCmd.SetParameters(sqlParams).SelectLazy<T>(sql))
509+
yield return p;
509510
}
510511

511512
internal static IEnumerable<T> SelectLazy<T>(this IDbCommand dbCmd, string sql, object anonType = null)

tests/ServiceStack.OrmLite.Tests/UseCase/ArtistTrackSqlExpressions.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,5 +60,17 @@ public void Can_Select_joined_table_with_Alias()
6060
Assert.That(tracksByYear.Map(x => x.Value).Sum(), Is.EqualTo(8));
6161
}
6262
}
63+
64+
[Test]
65+
public void Can_Count_Distinct()
66+
{
67+
using (var db = CreateArtistAndTrackTablesWithData(OpenDbConnection()))
68+
{
69+
var differentArtistsCount = db.Scalar<int>(db.From<Track>()
70+
.Select(x => Sql.CountDistinct(x.ArtistId)));
71+
72+
Assert.That(differentArtistsCount, Is.EqualTo(4));
73+
}
74+
}
6375
}
6476
}

0 commit comments

Comments
 (0)