From: <pa...@us...> - 2011-01-17 05:55:54
|
Revision: 5360 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5360&view=rev Author: patearl Date: 2011-01-17 05:55:48 +0000 (Mon, 17 Jan 2011) Log Message: ----------- Linq: Fixed caching related to generic method calls. (NH-2433, Thanks to Dean Ward for patch.) Modified Paths: -------------- trunk/nhibernate/src/NHibernate/Linq/Visitors/ExpressionKeyVisitor.cs trunk/nhibernate/src/NHibernate.Test/Linq/ParameterisedQueries.cs Modified: trunk/nhibernate/src/NHibernate/Linq/Visitors/ExpressionKeyVisitor.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Linq/Visitors/ExpressionKeyVisitor.cs 2011-01-17 04:39:24 UTC (rev 5359) +++ trunk/nhibernate/src/NHibernate/Linq/Visitors/ExpressionKeyVisitor.cs 2011-01-17 05:55:48 UTC (rev 5360) @@ -1,6 +1,8 @@ using System.Collections.Generic; using System.Collections.ObjectModel; +using System.Linq; using System.Linq.Expressions; +using System.Reflection; using System.Text; namespace NHibernate.Linq.Visitors @@ -42,7 +44,7 @@ { _string.Append(expression.Method.DeclaringType.Name); _string.Append("."); - _string.Append(expression.Method.Name); + VisitMethod(expression.Method); } else { @@ -85,7 +87,10 @@ } else { - _string.Append(expression.Value); + if (expression.Value == null) + _string.Append("NULL"); + else + _string.Append(expression.Value); } return base.VisitConstantExpression(expression); @@ -165,7 +170,7 @@ { VisitExpression(expression.Object); _string.Append('.'); - _string.Append(expression.Method.Name); + VisitMethod(expression.Method); _string.Append('('); VisitList(expression.Arguments, AppendCommas); _string.Append(')'); @@ -221,5 +226,16 @@ { return base.VisitUnknownExpression(expression); } + + private void VisitMethod(MethodInfo methodInfo) + { + _string.Append(methodInfo.Name); + if (methodInfo.IsGenericMethod) + { + _string.Append('['); + _string.Append(string.Join(",", methodInfo.GetGenericArguments().Select(a => a.FullName).ToArray())); + _string.Append(']'); + } + } } } \ No newline at end of file Modified: trunk/nhibernate/src/NHibernate.Test/Linq/ParameterisedQueries.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/Linq/ParameterisedQueries.cs 2011-01-17 04:39:24 UTC (rev 5359) +++ trunk/nhibernate/src/NHibernate.Test/Linq/ParameterisedQueries.cs 2011-01-17 05:55:48 UTC (rev 5360) @@ -169,6 +169,42 @@ } } + [Test] + public void Different_OfType_Returns_Different_Keys() + { + using (var session = OpenSession()) + { + Expression<Func<IEnumerable>> ofType1 = () => (from a in session.Query<Animal>().OfType<Cat>() where a.Pregnant select a.Id); + Expression<Func<IEnumerable>> ofType2 = () => (from a in session.Query<Animal>().OfType<Dog>() where a.Pregnant select a.Id); + + var nhOfType1 = new NhLinqExpression(ofType1.Body); + var nhOfType2 = new NhLinqExpression(ofType2.Body); + + Assert.AreNotEqual(nhOfType1.Key, nhOfType2.Key); + } + } + + [Test] + public void Different_Null_Returns_Different_Keys() + { + using (var session = OpenSession()) + { + string nullVariable = null; + string notNullVariable = "Hello"; + + Expression<Func<IEnumerable>> null1 = () => (from a in session.Query<Animal>() where a.Description == null select a); + Expression<Func<IEnumerable>> null2 = () => (from a in session.Query<Animal>() where a.Description == nullVariable select a); + Expression<Func<IEnumerable>> notNull = () => (from a in session.Query<Animal>() where a.Description == notNullVariable select a); + + var nhNull1 = new NhLinqExpression(null1.Body); + var nhNull2 = new NhLinqExpression(null2.Body); + var nhNotNull = new NhLinqExpression(notNull.Body); + + Assert.AreNotEqual(nhNull1.Key, nhNotNull.Key); + Assert.AreNotEqual(nhNull2.Key, nhNotNull.Key); + } + } + // TODO - different parameter names protected override IList Mappings This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |