Skip to content

Commit 6a58fa5

Browse files
committed
1 parent 8dfe60f commit 6a58fa5

2 files changed

Lines changed: 20 additions & 0 deletions

File tree

Simple.Data.BehaviourTest/Query/QueryTest.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,5 +228,17 @@ public void SpecifyingJoinTableShouldCreateDirectQuery()
228228
GeneratedSqlIs("select [dbo].[userbio].[userid],[dbo].[userbio].[text] from [dbo].[userbio]" +
229229
" join [dbo].[users] on ([dbo].[users].[id] = [dbo].[userbio].[userid]) where [dbo].[users].[id] = @p1");
230230
}
231+
232+
[Test]
233+
public void SpecifyOrderByWithoutReferenceThrowsException()
234+
{
235+
Assert.Throws<ArgumentException>(() => _db.Users.All().OrderBy(1));
236+
}
237+
238+
[Test]
239+
public void SpecifyOrderByDescendingWithoutReferenceThrowsException()
240+
{
241+
Assert.Throws<ArgumentException>(() => _db.Users.All().OrderByDescending(1));
242+
}
231243
}
232244
}

Simple.Data/SimpleQuery.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -650,9 +650,17 @@ private SimpleQuery AddNewJoin(JoinClause newJoin)
650650
private SimpleQuery ParseOrderBy(string methodName)
651651
{
652652
methodName = Regex.Replace(methodName, "^order_?by_?", "", RegexOptions.IgnoreCase);
653+
if (string.IsNullOrWhiteSpace(methodName))
654+
{
655+
throw new ArgumentException("Invalid arguments to OrderBy");
656+
}
653657
if (methodName.EndsWith("descending", StringComparison.OrdinalIgnoreCase))
654658
{
655659
methodName = Regex.Replace(methodName, "_?descending$", "", RegexOptions.IgnoreCase);
660+
if (string.IsNullOrWhiteSpace(methodName))
661+
{
662+
throw new ArgumentException("Invalid arguments to OrderByDescending");
663+
}
656664
return OrderByDescending(ObjectReference.FromString(_tableName + "." + methodName));
657665
}
658666
return OrderBy(ObjectReference.FromString(_tableName + "." + methodName));

0 commit comments

Comments
 (0)