|
From: <fab...@us...> - 2010-10-09 11:29:30
|
Revision: 5240
http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5240&view=rev
Author: fabiomaulo
Date: 2010-10-09 11:29:22 +0000 (Sat, 09 Oct 2010)
Log Message:
-----------
Fix NH-2001 (thanks to Ricardo Stuven)
Modified Paths:
--------------
trunk/nhibernate/src/NHibernate/Linq/Visitors/HqlGeneratorExpressionTreeVisitor.cs
trunk/nhibernate/src/NHibernate.Test/Linq/LinqQuerySamples.cs
Modified: trunk/nhibernate/src/NHibernate/Linq/Visitors/HqlGeneratorExpressionTreeVisitor.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Linq/Visitors/HqlGeneratorExpressionTreeVisitor.cs 2010-10-07 23:56:06 UTC (rev 5239)
+++ trunk/nhibernate/src/NHibernate/Linq/Visitors/HqlGeneratorExpressionTreeVisitor.cs 2010-10-09 11:29:22 UTC (rev 5240)
@@ -239,6 +239,13 @@
var lhs2 = VisitExpression(expression.Left).AsExpression();
var rhs2 = VisitExpression(expression.Right).AsExpression();
+ if (expression.Right is ConstantExpression
+ && expression.Right.Type.IsNullableOrReference()
+ && ((ConstantExpression)expression.Right).Value == null)
+ {
+ return _hqlTreeBuilder.IsNull(lhs2);
+ }
+
return _hqlTreeBuilder.BooleanOr(
_hqlTreeBuilder.BooleanAnd(
_hqlTreeBuilder.IsNull(lhs),
@@ -275,6 +282,13 @@
var lhs3 = VisitExpression(expression.Left).AsExpression();
var rhs3 = VisitExpression(expression.Right).AsExpression();
+ if (expression.Right is ConstantExpression
+ && expression.Right.Type.IsNullableOrReference()
+ && ((ConstantExpression)expression.Right).Value == null)
+ {
+ return _hqlTreeBuilder.IsNotNull(lhs2);
+ }
+
return
_hqlTreeBuilder.BooleanOr(
_hqlTreeBuilder.BooleanOr(
Modified: trunk/nhibernate/src/NHibernate.Test/Linq/LinqQuerySamples.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/Linq/LinqQuerySamples.cs 2010-10-07 23:56:06 UTC (rev 5239)
+++ trunk/nhibernate/src/NHibernate.Test/Linq/LinqQuerySamples.cs 2010-10-09 11:29:22 UTC (rev 5240)
@@ -1564,6 +1564,48 @@
ObjectDumper.Write(q);
}
+
+ [Category("WHERE")]
+ [Test(Description = "This sample uses WHERE to filter for orders with shipping date equals to null.")]
+ public void DLinq2B()
+ {
+ IQueryable<Order> q =
+ from o in db.Orders
+ where o.ShippingDate == null
+ select o;
+
+ AssertByIds(q,
+ new[]
+ {
+ 11008, 11019, 11039, 11040, 11045, 11051, 11054,
+ 11058, 11059, 11061, 11062, 11065, 11068, 11070,
+ 11071, 11072, 11073, 11074, 11075, 11076, 11077
+ },
+ x => x.OrderId);
+ }
+
+ [Category("WHERE")]
+ [Test(Description = "This sample uses WHERE to filter for orders with shipping date not equals to null.")]
+ public void DLinq2C()
+ {
+ var q =
+ (from o in db.Orders
+ where o.ShippingDate != null
+ select o.OrderId).ToArray();
+
+
+ var withNullShippingDate =
+ new[]
+ {
+ 11008, 11019, 11039, 11040, 11045, 11051, 11054,
+ 11058, 11059, 11061, 11062, 11065, 11068, 11070,
+ 11071, 11072, 11073, 11074, 11075, 11076, 11077
+ };
+
+ Assert.AreEqual(809, q.Length);
+
+ Assert.That(!q.Any(orderid => withNullShippingDate.Contains(orderid)));
+ }
}
public class ParentChildBatch<T, TKey, TSub>
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|