|
From: <ric...@us...> - 2009-07-29 18:46:51
|
Revision: 4668
http://nhibernate.svn.sourceforge.net/nhibernate/?rev=4668&view=rev
Author: ricbrown
Date: 2009-07-29 18:46:44 +0000 (Wed, 29 Jul 2009)
Log Message:
-----------
Added handling for Lambda syntax allowing path including collections.
Modified Paths:
--------------
trunk/nhibernate/src/NHibernate/Impl/ExpressionProcessor.cs
trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/ExpressionProcessorFixture.cs
trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/Model.cs
Modified: trunk/nhibernate/src/NHibernate/Impl/ExpressionProcessor.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Impl/ExpressionProcessor.cs 2009-07-28 20:09:38 UTC (rev 4667)
+++ trunk/nhibernate/src/NHibernate/Impl/ExpressionProcessor.cs 2009-07-29 18:46:44 UTC (rev 4668)
@@ -121,10 +121,15 @@
{
MemberExpression memberExpression = (MemberExpression)expression;
- if (memberExpression.Expression.NodeType == ExpressionType.MemberAccess)
+ if (memberExpression.Expression.NodeType == ExpressionType.MemberAccess
+ || memberExpression.Expression.NodeType == ExpressionType.Call)
+ {
return FindMemberExpression(memberExpression.Expression) + "." + memberExpression.Member.Name;
+ }
else
+ {
return memberExpression.Member.Name;
+ }
}
if (expression is UnaryExpression)
@@ -149,6 +154,12 @@
return "class";
}
+ if (methodCallExpression.Method.Name == "get_Item")
+ return FindMemberExpression(methodCallExpression.Object);
+
+ if (methodCallExpression.Method.Name == "First")
+ return FindMemberExpression(methodCallExpression.Arguments[0]);
+
throw new Exception("Unrecognised method call in epression " + expression.ToString());
}
Modified: trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/ExpressionProcessorFixture.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/ExpressionProcessorFixture.cs 2009-07-28 20:09:38 UTC (rev 4667)
+++ trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/ExpressionProcessorFixture.cs 2009-07-29 18:46:44 UTC (rev 4668)
@@ -1,5 +1,6 @@
using System;
+using System.Linq;
using System.Linq.Expressions;
using NHibernate.Criterion;
@@ -31,6 +32,22 @@
}
[Test]
+ public void TestFindMemberExpressionSubCollectionIndex()
+ {
+ Expression<Func<Person, object>> e = (Person p) => p.PersonList[0].Children;
+ string property = ExpressionProcessor.FindMemberExpression(e.Body);
+ Assert.AreEqual("PersonList.Children", property);
+ }
+
+ [Test]
+ public void TestFindMemberExpressionSubCollectionExtensionMethod()
+ {
+ Expression<Func<Person, object>> e = (Person p) => p.PersonList.First().Children;
+ string property = ExpressionProcessor.FindMemberExpression(e.Body);
+ Assert.AreEqual("PersonList.Children", property);
+ }
+
+ [Test]
public void TestEvaluatePropertyExpression()
{
string testName = "testName";
Modified: trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/Model.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/Model.cs 2009-07-28 20:09:38 UTC (rev 4667)
+++ trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/Model.cs 2009-07-29 18:46:44 UTC (rev 4668)
@@ -25,6 +25,7 @@
public virtual bool IsParent { get; set; }
public virtual IEnumerable<Child> Children { get; set; }
+ public virtual IList<Person> PersonList { get; set; }
}
public class CustomPerson : Person { }
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|