Skip to content

Commit 3299f80

Browse files
committed
Added BadExpressionException in Join.On, fixes ThatRendle#233
1 parent 54581ae commit 3299f80

2 files changed

Lines changed: 28 additions & 1 deletion

File tree

Simple.Data.BehaviourTest/Query/ExplicitJoinTest.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,20 @@ public void TwoJoins()
276276
"WHERE (([dbo].[Activity].[ID_Trip] = @p1 AND [dbo].[Activity].[Activity_Time] = @p2) AND [dbo].[Activity].[Is_Public] = @p3)");
277277
}
278278

279+
[Test]
280+
public void PassingTrueToOnThrowsBadExpressionException()
281+
{
282+
Assert.Throws<BadExpressionException>(
283+
() => _db.Activity.All().Join(_db.Location).On(true));
284+
}
285+
286+
[Test]
287+
public void PassingObjectReferenceToOnThrowsBadExpressionException()
288+
{
289+
Assert.Throws<BadExpressionException>(
290+
() => _db.Activity.All().Join(_db.Location).On(_db.Location.ID_Location));
291+
}
292+
279293
class Activity
280294
{
281295
public int ID_Activity { get; set; }

Simple.Data/SimpleQuery.cs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -514,7 +514,13 @@ public SimpleQuery OuterJoin(ObjectReference objectReference, out dynamic queryO
514514
public SimpleQuery On(SimpleExpression joinExpression)
515515
{
516516
if (_tempJoinWaitingForOn == null)
517+
{
517518
throw new InvalidOperationException("Call to On must be preceded by call to JoinInfo.");
519+
}
520+
if (ReferenceEquals(joinExpression, null))
521+
{
522+
throw new BadExpressionException("On expects an expression or named parameters.");
523+
}
518524
return AddNewJoin(new JoinClause(_tempJoinWaitingForOn.Table, _tempJoinWaitingForOn.JoinType, joinExpression));
519525
}
520526

@@ -561,9 +567,16 @@ private SimpleQuery ParseJoin(InvokeMemberBinder binder, object[] args)
561567
private SimpleQuery ParseOn(InvokeMemberBinder binder, IEnumerable<object> args)
562568
{
563569
if (_tempJoinWaitingForOn == null)
570+
{
564571
throw new InvalidOperationException("Call to On must be preceded by call to JoinInfo.");
572+
}
573+
var namedArguments = binder.NamedArgumentsToDictionary(args);
574+
if (namedArguments == null || namedArguments.Count == 0)
575+
{
576+
throw new BadExpressionException("On expects an expression or named parameters.");
577+
}
565578
var joinExpression = ExpressionHelper.CriteriaDictionaryToExpression(_tempJoinWaitingForOn.Table,
566-
binder.NamedArgumentsToDictionary(args));
579+
namedArguments);
567580
return AddNewJoin(new JoinClause(_tempJoinWaitingForOn.Table, _tempJoinWaitingForOn.JoinType, joinExpression));
568581
}
569582

0 commit comments

Comments
 (0)