|
From: <fab...@us...> - 2011-05-20 13:58:59
|
Revision: 5841
http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5841&view=rev
Author: fabiomaulo
Date: 2011-05-20 13:58:52 +0000 (Fri, 20 May 2011)
Log Message:
-----------
Fix NH-2717 and NH-2708
Modified Paths:
--------------
trunk/nhibernate/src/NHibernate/Linq/ReWriters/RemoveUnnecessaryBodyOperators.cs
trunk/nhibernate/src/NHibernate/Linq/ReWriters/ResultOperatorRewriter.cs
trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj
Added Paths:
-----------
trunk/nhibernate/src/NHibernate.Test/Linq/ByMethod/CastTests.cs
Modified: trunk/nhibernate/src/NHibernate/Linq/ReWriters/RemoveUnnecessaryBodyOperators.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Linq/ReWriters/RemoveUnnecessaryBodyOperators.cs 2011-05-18 18:47:08 UTC (rev 5840)
+++ trunk/nhibernate/src/NHibernate/Linq/ReWriters/RemoveUnnecessaryBodyOperators.cs 2011-05-20 13:58:52 UTC (rev 5841)
@@ -1,4 +1,5 @@
-using System.Linq;
+using System;
+using System.Linq;
using Remotion.Linq;
using Remotion.Linq.Clauses;
using Remotion.Linq.Clauses.ResultOperators;
@@ -26,6 +27,10 @@
queryModel.BodyClauses.Remove(orderby);
}
}
+ if (resultOperator is CastResultOperator)
+ {
+ Array.ForEach(queryModel.ResultOperators.OfType<CastResultOperator>().ToArray(), castOperator=> queryModel.ResultOperators.Remove(castOperator));
+ }
base.VisitResultOperator(resultOperator, queryModel, index);
}
Modified: trunk/nhibernate/src/NHibernate/Linq/ReWriters/ResultOperatorRewriter.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Linq/ReWriters/ResultOperatorRewriter.cs 2011-05-18 18:47:08 UTC (rev 5840)
+++ trunk/nhibernate/src/NHibernate/Linq/ReWriters/ResultOperatorRewriter.cs 2011-05-20 13:58:52 UTC (rev 5841)
@@ -64,6 +64,7 @@
typeof(FetchRequestBase),
typeof(OfTypeResultOperator),
typeof(CacheableResultOperator),
+ typeof(CastResultOperator), // see ProcessCast class
};
private readonly List<ResultOperatorBase> resultOperators = new List<ResultOperatorBase>();
Added: trunk/nhibernate/src/NHibernate.Test/Linq/ByMethod/CastTests.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/Linq/ByMethod/CastTests.cs (rev 0)
+++ trunk/nhibernate/src/NHibernate.Test/Linq/ByMethod/CastTests.cs 2011-05-20 13:58:52 UTC (rev 5841)
@@ -0,0 +1,45 @@
+using System.Linq;
+using NHibernate.DomainModel.Northwind.Entities;
+using NHibernate.Linq;
+using NUnit.Framework;
+using SharpTestsEx;
+
+namespace NHibernate.Test.Linq.ByMethod
+{
+ public class CastTests : LinqTestCase
+ {
+ [Test]
+ public void CastCount()
+ {
+ session.Query<Cat>()
+ .Cast<Animal>()
+ .Count().Should().Be(1);
+ }
+
+ [Test]
+ public void CastWithWhere()
+ {
+ var pregnatMammal = (from a
+ in session.Query<Animal>().Cast<Cat>()
+ where a.Pregnant
+ select a).FirstOrDefault();
+ pregnatMammal.Should().Not.Be.Null();
+ }
+
+ [Test]
+ public void CastDowncast()
+ {
+ var query = session.Query<Mammal>().Cast<Dog>();
+ // the list contains at least one Cat then should Throws
+ query.Executing(q=> q.ToList()).Throws();
+ }
+
+ [Test, Ignore("Not fixed yet. The method OfType does not work as expected.")]
+ public void CastDowncastUsingOfType()
+ {
+ var query = session.Query<Animal>().OfType<Mammal>().Cast<Dog>();
+ // the list contains at least one Cat then should Throws
+ query.Executing(q => q.ToList()).Throws();
+ }
+ }
+}
\ No newline at end of file
Modified: trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2011-05-18 18:47:08 UTC (rev 5840)
+++ trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2011-05-20 13:58:52 UTC (rev 5841)
@@ -481,6 +481,7 @@
<Compile Include="Linq\BinaryBooleanExpressionTests.cs" />
<Compile Include="Linq\BinaryExpressionOrdererTests.cs" />
<Compile Include="Linq\BooleanMethodExtensionExample.cs" />
+ <Compile Include="Linq\ByMethod\CastTests.cs" />
<Compile Include="Linq\ByMethod\GroupByTests.cs" />
<Compile Include="Linq\CasingTest.cs" />
<Compile Include="Linq\CollectionAssert.cs" />
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|