Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Supporting projecting of complex paths

  • Loading branch information...
commit 6e425778e50d8ce24d685ed6c763c2fc91422911 1 parent c6f8f61
Ayende Rahien ayende authored
18 Raven.Client.Lightweight/Linq/RavenQueryProviderProcessor.cs
View
@@ -860,8 +860,9 @@ private void VisitSelect(Expression operand)
var field = newExpression.Arguments[index] as MemberExpression;
if(field == null)
continue;
-
- AddToFieldsToFetch(field.Member.Name, newExpression.Members[index].Name);
+ var expression = GetMemberExpression(newExpression.Arguments[index]);
+ var renamedField = GetSelectPath(expression);
+ AddToFieldsToFetch(renamedField, newExpression.Members[index].Name);
}
break;
//for example .Select(x => new SomeType { x.Cost } ), it's member init because it's using the object initializer
@@ -885,6 +886,19 @@ private void VisitSelect(Expression operand)
}
}
+ private string GetSelectPath(MemberExpression expression)
+ {
+ var sb = new StringBuilder(expression.Member.Name);
+ expression = expression.Expression as MemberExpression;
+ while ( expression != null)
+ {
+ sb.Insert(0, ".");
+ sb.Insert(0, expression.Member.Name);
+ expression = expression.Expression as MemberExpression;
+ }
+ return sb.ToString();
+ }
+
private void AddToFieldsToFetch(string docField, string renamedField)
{
var identityProperty = luceneQuery.DocumentConvention.GetIdentityProperty(typeof(T));
51 Raven.Tests/MailingList/ListCount.cs
View
@@ -0,0 +1,51 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using Xunit;
+
+namespace Raven.Tests.MailingList
+{
+ public class ListCount : RavenTest
+ {
+ public class Location
+ {
+ public Guid Id { get; set; }
+
+ public string Name { get; set; }
+
+ public List<Guid> Properties { get; set; }
+ }
+
+ [Fact]
+ public void CanGetCount()
+ {
+ using(var store = NewDocumentStore())
+ {
+ using(var session = store.OpenSession())
+ {
+ session.Store(new Location
+ {
+ Properties = new List<Guid>
+ {
+ Guid.NewGuid(),
+ Guid.NewGuid()
+ },
+ Name = "Ayende"
+ });
+ session.SaveChanges();
+
+ var result = session.Query<Location>()
+ .Where(x => x.Name.StartsWith("ay"))
+ .Select(x => new
+ {
+ x.Name,
+ x.Properties.Count
+ }).ToList();
+
+ Assert.Equal("Ayende", result[0].Name);
+ Assert.Equal(2, result[0].Count);
+ }
+ }
+ }
+ }
+}
1  Raven.Tests/Raven.Tests.csproj
View
@@ -565,6 +565,7 @@
<Compile Include="MailingList\HierarchicalInheritanceIndexing.cs" />
<Compile Include="MailingList\IisQueryLengthIssues.cs" />
<Compile Include="MailingList\JohanNilsson.cs" />
+ <Compile Include="MailingList\ListCount.cs" />
<Compile Include="MailingList\MapReduceIssue\CanPageThroughReduceResults.cs" />
<Compile Include="MailingList\DynamicQueryIndexSelection.cs" />
<Compile Include="MailingList\EnumAsInts.cs" />
Please sign in to comment.
Something went wrong with that request. Please try again.