Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Early warning when you are trying to use invalid computations

  • Loading branch information...
commit 4e0014e2de335ea91f5693b888081d7025f99b94 1 parent fca8cbe
@ayende authored
View
39 Raven.Client.Lightweight/Linq/RavenQueryProviderProcessor.cs
@@ -386,12 +386,51 @@ protected void GetPath(Expression expression, out string path, out Type memberTy
else
{
var memberExpression = GetMemberExpression(expression);
+
+ AssertNoComputation(memberExpression);
+
path = memberExpression.ToString();
isNestedPath = memberExpression.Expression is MemberExpression;
memberType = memberExpression.Member.GetMemberType();
}
}
+ private void AssertNoComputation(MemberExpression memberExpression)
+ {
+ var cur = memberExpression;
+
+ while (cur != null)
+ {
+ switch (cur.Expression.NodeType)
+ {
+ case ExpressionType.Call:
+ case ExpressionType.Invoke:
+ case ExpressionType.Add:
+ case ExpressionType.Decrement:
+ case ExpressionType.Increment:
+ case ExpressionType.PostDecrementAssign:
+ case ExpressionType.PostIncrementAssign:
+ case ExpressionType.PreDecrementAssign:
+ case ExpressionType.PreIncrementAssign:
+ case ExpressionType.And:
+ case ExpressionType.AndAlso:
+ case ExpressionType.AndAssign:
+ case ExpressionType.AddAssign:
+ case ExpressionType.AddAssignChecked:
+ case ExpressionType.AddChecked:
+ case ExpressionType.Assign:
+ case ExpressionType.Block:
+ case ExpressionType.Conditional:
+ case ExpressionType.ArrayIndex:
+ case ExpressionType.Index:
+
+ throw new ArgumentException("Invalid computation: " + memberExpression +
+ ". You cannot use computation (only simple member expression are allowed) in RavenDB queries.");
+ }
+ cur = cur.Expression as MemberExpression;
+ }
+ }
+
/// <summary>
/// Get the member expression from the expression
/// </summary>
View
35 Raven.Tests/MailingList/Wallace.cs
@@ -0,0 +1,35 @@
+// -----------------------------------------------------------------------
+// <copyright file="Wallace.cs" company="Hibernating Rhinos LTD">
+// Copyright (c) Hibernating Rhinos LTD. All rights reserved.
+// </copyright>
+// -----------------------------------------------------------------------
+using System;
+using Raven.Client.Document;
+using Raven.Tests.Indexes;
+using Xunit;
+using Raven.Client.Linq;
+using System.Linq;
+
+namespace Raven.Tests.MailingList
+{
+ public class Wallace : RavenTest
+ {
+ [Fact]
+ public void CanGetProperErrorFromComputedOrderBy()
+ {
+ using(GetNewServer())
+ using(var store = new DocumentStore
+ {
+ Url = "http://localhost:8079"
+ }.Initialize())
+ {
+ using(var session = store.OpenSession())
+ {
+ var argumentException = Assert.Throws<ArgumentException>(() => session.Query<LinqIndexesFromClient.Order>().OrderBy(x => x.OrderLines.Last().Quantity).ToList());
+
+ Assert.Equal("Invalid computation: x.OrderLines.Last().Quantity. You cannot use computation (only simple member expression are allowed) in RavenDB queries.", argumentException.Message);
+ }
+ }
+ }
+ }
+}
View
1  Raven.Tests/Raven.Tests.csproj
@@ -658,6 +658,7 @@
<Compile Include="MailingList\Victor.cs" />
<Compile Include="MailingList\Vitaly.cs" />
<Compile Include="MailingList\Vlad.cs" />
+ <Compile Include="MailingList\Wallace.cs" />
<Compile Include="MailingList\Weave.cs" />
<Compile Include="ManagedStorage\Attachments.cs">
<SubType>Code</SubType>
Please sign in to comment.
Something went wrong with that request. Please try again.