|
From: <ric...@us...> - 2011-05-22 14:59:04
|
Revision: 5854
http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5854&view=rev
Author: ricbrown
Date: 2011-05-22 14:58:58 +0000 (Sun, 22 May 2011)
Log Message:
-----------
NH-2683: Updated Sqrt() QueryOver extension to return double
Modified Paths:
--------------
trunk/nhibernate/src/NHibernate/Criterion/ProjectionsExtensions.cs
trunk/nhibernate/src/NHibernate/Impl/ExpressionProcessor.cs
trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/IntegrationFixture.cs
trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/RestrictionsFixture.cs
Modified: trunk/nhibernate/src/NHibernate/Criterion/ProjectionsExtensions.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Criterion/ProjectionsExtensions.cs 2011-05-22 14:22:22 UTC (rev 5853)
+++ trunk/nhibernate/src/NHibernate/Criterion/ProjectionsExtensions.cs 2011-05-22 14:58:58 UTC (rev 5854)
@@ -119,70 +119,46 @@
throw new Exception("Not to be used directly - use inside QueryOver expression");
}
- internal static IProjection ProcessDoubleSqrt(MethodCallExpression methodCallExpression)
- {
- IProjection property = ExpressionProcessor.FindMemberProjection(methodCallExpression.Arguments[0]);
- return Projections.SqlFunction("sqrt", NHibernateUtil.Double, property);
- }
-
/// <summary>
/// Project SQL function sqrt()
/// Note: throws an exception outside of a QueryOver expression
/// </summary>
- public static int Sqrt(this int numericProperty)
+ public static double Sqrt(this int numericProperty)
{
throw new Exception("Not to be used directly - use inside QueryOver expression");
}
- internal static IProjection ProcessIntSqrt(MethodCallExpression methodCallExpression)
- {
- IProjection property = ExpressionProcessor.FindMemberProjection(methodCallExpression.Arguments[0]);
- return Projections.SqlFunction("sqrt", NHibernateUtil.Int32, property);
- }
-
/// <summary>
/// Project SQL function sqrt()
/// Note: throws an exception outside of a QueryOver expression
/// </summary>
- public static Int64 Sqrt(this Int64 numericProperty)
+ public static double Sqrt(this long numericProperty)
{
throw new Exception("Not to be used directly - use inside QueryOver expression");
}
- internal static IProjection ProcessInt64Sqrt(MethodCallExpression methodCallExpression)
- {
- IProjection property = ExpressionProcessor.FindMemberProjection(methodCallExpression.Arguments[0]);
- return Projections.SqlFunction("sqrt", NHibernateUtil.Int64, property);
- }
-
/// <summary>
/// Project SQL function sqrt()
/// Note: throws an exception outside of a QueryOver expression
/// </summary>
- public static decimal Sqrt(this decimal numericProperty)
+ public static double Sqrt(this decimal numericProperty)
{
throw new Exception("Not to be used directly - use inside QueryOver expression");
}
- internal static IProjection ProcessDecimalSqrt(MethodCallExpression methodCallExpression)
- {
- IProjection property = ExpressionProcessor.FindMemberProjection(methodCallExpression.Arguments[0]);
- return Projections.SqlFunction("sqrt", NHibernateUtil.Decimal, property);
- }
-
/// <summary>
/// Project SQL function sqrt()
/// Note: throws an exception outside of a QueryOver expression
/// </summary>
- public static byte Sqrt(this byte numericProperty)
+ public static double Sqrt(this byte numericProperty)
{
throw new Exception("Not to be used directly - use inside QueryOver expression");
}
- internal static IProjection ProcessByteSqrt(MethodCallExpression methodCallExpression)
+ internal static IProjection ProcessSqrt(MethodCallExpression methodCallExpression)
{
IProjection property = ExpressionProcessor.FindMemberProjection(methodCallExpression.Arguments[0]);
- return Projections.SqlFunction("sqrt", NHibernateUtil.Byte, property);
+ return Projections.SqlFunction("sqrt", NHibernateUtil.Double, property);
}
/// <summary>
Modified: trunk/nhibernate/src/NHibernate/Impl/ExpressionProcessor.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Impl/ExpressionProcessor.cs 2011-05-22 14:22:22 UTC (rev 5853)
+++ trunk/nhibernate/src/NHibernate/Impl/ExpressionProcessor.cs 2011-05-22 14:58:58 UTC (rev 5854)
@@ -95,11 +95,11 @@
RegisterCustomProjection(() => ProjectionsExtensions.HourPart(default(DateTime)), ProjectionsExtensions.ProcessHourPart);
RegisterCustomProjection(() => ProjectionsExtensions.MinutePart(default(DateTime)), ProjectionsExtensions.ProcessMinutePart);
RegisterCustomProjection(() => ProjectionsExtensions.SecondPart(default(DateTime)), ProjectionsExtensions.ProcessSecondPart);
- RegisterCustomProjection(() => ProjectionsExtensions.Sqrt(default(int)), ProjectionsExtensions.ProcessIntSqrt);
- RegisterCustomProjection(() => ProjectionsExtensions.Sqrt(default(double)), ProjectionsExtensions.ProcessDoubleSqrt);
- RegisterCustomProjection(() => ProjectionsExtensions.Sqrt(default(decimal)), ProjectionsExtensions.ProcessDecimalSqrt);
- RegisterCustomProjection(() => ProjectionsExtensions.Sqrt(default(byte)), ProjectionsExtensions.ProcessByteSqrt);
- RegisterCustomProjection(() => ProjectionsExtensions.Sqrt(default(Int64)), ProjectionsExtensions.ProcessInt64Sqrt);
+ RegisterCustomProjection(() => ProjectionsExtensions.Sqrt(default(int)), ProjectionsExtensions.ProcessSqrt);
+ RegisterCustomProjection(() => ProjectionsExtensions.Sqrt(default(double)), ProjectionsExtensions.ProcessSqrt);
+ RegisterCustomProjection(() => ProjectionsExtensions.Sqrt(default(decimal)), ProjectionsExtensions.ProcessSqrt);
+ RegisterCustomProjection(() => ProjectionsExtensions.Sqrt(default(byte)), ProjectionsExtensions.ProcessSqrt);
+ RegisterCustomProjection(() => ProjectionsExtensions.Sqrt(default(long)), ProjectionsExtensions.ProcessSqrt);
RegisterCustomProjection(() => ProjectionsExtensions.Lower(string.Empty), ProjectionsExtensions.ProcessLower);
RegisterCustomProjection(() => ProjectionsExtensions.Upper(string.Empty), ProjectionsExtensions.ProcessUpper);
RegisterCustomProjection(() => ProjectionsExtensions.TrimStr(string.Empty), ProjectionsExtensions.ProcessTrimStr);
Modified: trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/IntegrationFixture.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/IntegrationFixture.cs 2011-05-22 14:22:22 UTC (rev 5853)
+++ trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/IntegrationFixture.cs 2011-05-22 14:58:58 UTC (rev 5854)
@@ -573,7 +573,7 @@
using (ISession s = OpenSession())
using (ITransaction t = s.BeginTransaction())
{
- s.Save(new Person() { Name = "p1", BirthDate = new DateTime(2009, 08, 07) });
+ s.Save(new Person() { Name = "p1", BirthDate = new DateTime(2009, 08, 07), Age = 90 });
s.Save(new Person() { Name = "p2", BirthDate = new DateTime(2008, 07, 06) });
s.Save(new Person() { Name = "p3", BirthDate = new DateTime(2007, 06, 05) });
@@ -602,6 +602,18 @@
yearOfBirth.GetType().Should().Be(typeof(int));
yearOfBirth.Should().Be(2008);
}
+
+ using (ISession s = OpenSession())
+ {
+ var sqrtOfAge =
+ s.QueryOver<Person>()
+ .Where(p => p.Name == "p1")
+ .Select(p => p.Age.Sqrt())
+ .SingleOrDefault<object>();
+
+ sqrtOfAge.GetType().Should().Be(typeof(double));
+ string.Format("{0:0.00}", sqrtOfAge).Should().Be("9.49");
+ }
}
[Test]
Modified: trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/RestrictionsFixture.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/RestrictionsFixture.cs 2011-05-22 14:22:22 UTC (rev 5853)
+++ trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/RestrictionsFixture.cs 2011-05-22 14:58:58 UTC (rev 5854)
@@ -266,7 +266,7 @@
.Add(Restrictions.Eq(Projections.SqlFunction("hour", NHibernateUtil.Int32, Projections.Property("BirthDate")), 1))
.Add(Restrictions.Eq(Projections.SqlFunction("minute", NHibernateUtil.Int32, Projections.Property("BirthDate")), 1))
.Add(Restrictions.Eq(Projections.SqlFunction("second", NHibernateUtil.Int32, Projections.Property("BirthDate")), 1))
- .Add(Restrictions.Eq(Projections.SqlFunction("sqrt", NHibernateUtil.Int32, Projections.Property("Height")), 10))
+ .Add(Restrictions.Eq(Projections.SqlFunction("sqrt", NHibernateUtil.Double, Projections.Property("Height")), 10d))
.Add(Restrictions.Eq(Projections.SqlFunction("lower", NHibernateUtil.String, Projections.Property("Name")), "test"))
.Add(Restrictions.Eq(Projections.SqlFunction("upper", NHibernateUtil.String, Projections.Property("Name")), "TEST"))
.Add(Restrictions.Eq(Projections.SqlFunction("abs", NHibernateUtil.Int32, Projections.Property("Height")), 150))
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|