Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixing an issue where using long Id would generate invalid include path

  • Loading branch information...
commit e183e231d3319c803333ee9849ebdb855720c62f 1 parent 39a8640
@ayende ayende authored
View
26 Raven.Abstractions/Extensions/ExpressionExtensions.cs
@@ -7,12 +7,12 @@
using System.Collections.Generic;
using System.Linq.Expressions;
-namespace Raven.Abstractions.Extensions
+namespace Raven.Abstractions.Extensions
{
///<summary>
/// Extensions for Linq expressions
///</summary>
- public static class ExpressionExtensions
+ public static class ExpressionExtensions
{
///<summary>
/// Turn an expression like x=&lt; x.User.Name to "User.Name"
@@ -20,7 +20,27 @@ public static class ExpressionExtensions
///<param name="expr">Expression for member access</param>
public static string ToPropertyPath<T, TProperty>(this Expression<Func<T, TProperty>> expr)
{
- var me = expr.Body as MemberExpression;
+ var expression = expr.Body;
+
+ var unaryExpression = expression as UnaryExpression;
+ if (unaryExpression != null)
+ {
+ switch (unaryExpression.NodeType)
+ {
+ case ExpressionType.Convert:
+ case ExpressionType.ConvertChecked:
+ expression = unaryExpression.Operand;
+ break;
+ }
+
+ }
+
+ MemberExpression me = expression as MemberExpression;
+
+ if(me == null)
+ throw new InvalidOperationException("No idea how to convert " + expr.Body.NodeType + ", " + expr.Body +
+ " to a member expression");
+
var parts = new List<string>();
while (me != null)
{
View
84 Raven.Tests/MailingList/Phil-Updated.cs
@@ -0,0 +1,84 @@
+using System;
+using System.Collections.Generic;
+using Raven.Client.Document;
+using Xunit;
+
+namespace Raven.Tests.MailingList
+{
+ public class PhilUpdated : RavenTest
+ {
+ public class Item
+ {
+ public long Id { get; set; }
+
+ public string Stuff { get; set; }
+
+ public string Summary;
+ public long UserId;
+
+ public Item()
+ {
+
+ }
+ public Item(long userId, string stuff)
+ {
+ this.UserId = userId;
+ this.Stuff = stuff;
+ }
+ }
+ public class UserItem
+ {
+ public string Name;
+ public ItemReference Item;
+ }
+ public class User
+ {
+ public string FirstName, LastName;
+ public List<UserItem> UserItems;
+ public long Id { get; set; }
+ }
+
+ [Fact]
+ public void CanUseInclude_Remote()
+ {
+ using (GetNewServer())
+ using (var store = new DocumentStore
+ {
+ Url = "http://localhost:8079"
+ }.Initialize())
+ {
+ using (var s = store.OpenSession())
+ {
+ var user = new User { FirstName = "Demo", LastName = "User" };
+ s.Store(user);
+ var item = new Item(user.Id, "Stuff");
+ s.Store(item);
+ user.UserItems = new List<UserItem>
+ {
+ new UserItem
+ {
+ Item = new ItemReference {Id = item.Id, Summary = item.Summary, UserId = item.UserId},
+ Name = "Stuff 2"
+ }
+ };
+ s.SaveChanges();
+ }
+
+ using (var s = store.OpenSession())
+ {
+ var userLookup = s.Include<UserItem>(x => x.Item.Id).Load<User>(1);
+ foreach (var uit in userLookup.UserItems)
+ {
+ var item2 = s.Load<Item>(uit.Item.Id);
+ }
+ }
+ }
+ }
+
+ public class ItemReference
+ {
+ public long Id, UserId;
+ public string Summary;
+ }
+ }
+}
View
1  Raven.Tests/Raven.Tests.csproj
@@ -676,6 +676,7 @@
<Compile Include="Munin\ToDo.cs" />
<Compile Include="Munin\ToDoRepository.cs" />
<Compile Include="Patching\MetadataPatching.cs" />
+ <Compile Include="MailingList\Phil-Updated.cs" />
<Compile Include="Queries\Includes.cs" />
<Compile Include="Queries\ParameterisedDynamicQuery.cs" />
<Compile Include="Querying\IndexedUser.cs" />
Please sign in to comment.
Something went wrong with that request. Please try again.