Permalink
Browse files

Fix for issue #228

  • Loading branch information...
1 parent 52f477c commit 149841f0de44f6c78282f9ba62292d7681983413 @markrendle committed Nov 6, 2012
Showing with 22 additions and 1 deletion.
  1. +14 −0 Simple.Data.BehaviourTest/GetCountTest.cs
  2. +8 −1 Simple.Data/Commands/GetCountByCommand.cs
@@ -25,6 +25,20 @@ public void GetCountBasic()
}
[Test]
+ public void GetCountByBasic()
+ {
+ EatException<SimpleDataException>(() => _db.Users.GetCountByAge(42));
+ GeneratedSqlIs("select count(*) from [dbo].[users] where [dbo].[users].[age] = @p1");
+ }
+
+ [Test]
+ public void GetCountByNamedParameters()
+ {
+ EatException<SimpleDataException>(() => _db.Users.GetCountBy(Age: 42));
+ GeneratedSqlIs("select count(*) from [dbo].[users] where [dbo].[users].[age] = @p1");
+ }
+
+ [Test]
public void GetCountWithColumnThrowsException()
{
Assert.Throws<BadExpressionException>(() => _db.Users.GetCount(_db.Users.Id));
@@ -27,7 +27,14 @@ public bool IsCommandFor(string method)
/// <returns></returns>
public object Execute(DataStrategy dataStrategy, DynamicTable table, InvokeMemberBinder binder, object[] args)
{
- var criteria = ExpressionHelper.CriteriaDictionaryToExpression(table.GetQualifiedName(), MethodNameParser.ParseFromBinder(binder, args));
+ if (binder.Name.Equals("GetCountBy") || binder.Name.Equals("get_count_by"))
+ {
+ ArgumentHelper.CheckFindArgs(args, binder);
+ }
+
+ var criteriaDictionary = ArgumentHelper.CreateCriteriaDictionary(binder, args, "GetCountBy", "get_count_by");
+ var criteria = ExpressionHelper.CriteriaDictionaryToExpression(table.GetQualifiedName(),
+ criteriaDictionary);
return new SimpleQuery(dataStrategy, table.GetQualifiedName()).Where(criteria).Count();
}
}

0 comments on commit 149841f

Please sign in to comment.