Skip to content

Commit 149841f

Browse files
committed
Fix for issue ThatRendle#228
1 parent 52f477c commit 149841f

2 files changed

Lines changed: 22 additions & 1 deletion

File tree

Simple.Data.BehaviourTest/GetCountTest.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,20 @@ public void GetCountBasic()
2424
GeneratedSqlIs("select count(*) from [dbo].[users]");
2525
}
2626

27+
[Test]
28+
public void GetCountByBasic()
29+
{
30+
EatException<SimpleDataException>(() => _db.Users.GetCountByAge(42));
31+
GeneratedSqlIs("select count(*) from [dbo].[users] where [dbo].[users].[age] = @p1");
32+
}
33+
34+
[Test]
35+
public void GetCountByNamedParameters()
36+
{
37+
EatException<SimpleDataException>(() => _db.Users.GetCountBy(Age: 42));
38+
GeneratedSqlIs("select count(*) from [dbo].[users] where [dbo].[users].[age] = @p1");
39+
}
40+
2741
[Test]
2842
public void GetCountWithColumnThrowsException()
2943
{

Simple.Data/Commands/GetCountByCommand.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,14 @@ public bool IsCommandFor(string method)
2727
/// <returns></returns>
2828
public object Execute(DataStrategy dataStrategy, DynamicTable table, InvokeMemberBinder binder, object[] args)
2929
{
30-
var criteria = ExpressionHelper.CriteriaDictionaryToExpression(table.GetQualifiedName(), MethodNameParser.ParseFromBinder(binder, args));
30+
if (binder.Name.Equals("GetCountBy") || binder.Name.Equals("get_count_by"))
31+
{
32+
ArgumentHelper.CheckFindArgs(args, binder);
33+
}
34+
35+
var criteriaDictionary = ArgumentHelper.CreateCriteriaDictionary(binder, args, "GetCountBy", "get_count_by");
36+
var criteria = ExpressionHelper.CriteriaDictionaryToExpression(table.GetQualifiedName(),
37+
criteriaDictionary);
3138
return new SimpleQuery(dataStrategy, table.GetQualifiedName()).Where(criteria).Count();
3239
}
3340
}

0 commit comments

Comments
 (0)