Skip to content

Commit 4a98b94

Browse files
committed
Fixes issue ThatRendle#266
1 parent 5478456 commit 4a98b94

File tree

3 files changed

+22
-3
lines changed

3 files changed

+22
-3
lines changed

Simple.Data.BehaviourTest/GetCountTest.cs

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

27+
[Test]
28+
public void QueryCountBasic()
29+
{
30+
EatException<SimpleDataException>(() => _db.Users.All().Count());
31+
GeneratedSqlIs("select count(*) from [dbo].[users]");
32+
}
33+
2734
[Test]
2835
public void GetCountByBasic()
2936
{

Simple.Data.BehaviourTest/Query/ExplicitJoinTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ public void PassingObjectReferenceToOnThrowsBadExpressionException()
293293
[Test]
294294
public void PassingTablesWrongWayRoundThrowsBadExpressionException()
295295
{
296-
Assert.Throws<BadExpressionException>(
296+
Assert.Throws<BadJoinExpressionException>(
297297
() => _db.Activity.All().Join(_db.Activity, LocationId: _db.Location.ID_Location));
298298
}
299299

Simple.Data/Commands/ExistsCommand.cs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,21 @@ public object Execute(DataStrategy dataStrategy, DynamicTable table, InvokeMembe
2929
{
3030
var query = new SimpleQuery(dataStrategy, table.GetQualifiedName());
3131

32-
if (args.Length == 1 && args[0] is SimpleExpression)
32+
if (args.Length == 1)
3333
{
34-
query = query.Where((SimpleExpression)args[0]);
34+
var criteria = args[0] as SimpleExpression;
35+
if (criteria != null)
36+
{
37+
query = query.Where(criteria);
38+
}
39+
else
40+
{
41+
throw new BadExpressionException(binder.Name + " requires an expression.");
42+
}
43+
}
44+
else if (args.Length != 0)
45+
{
46+
throw new BadExpressionException(binder.Name + " requires an expression.");
3547
}
3648

3749
return query.Exists();

0 commit comments

Comments
 (0)