From: <ric...@us...> - 2011-05-22 13:28:58
|
Revision: 5852 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5852&view=rev Author: ricbrown Date: 2011-05-22 13:28:51 +0000 (Sun, 22 May 2011) Log Message: ----------- NH-2683: Added first cut of the remaining dialect functions (thanks to Vahid Nasiri for the patch). Modified Paths: -------------- trunk/nhibernate/src/NHibernate/Criterion/ProjectionsExtensions.cs trunk/nhibernate/src/NHibernate/Impl/ExpressionProcessor.cs trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/ExpressionProcessorFixture.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 11:02:26 UTC (rev 5851) +++ trunk/nhibernate/src/NHibernate/Criterion/ProjectionsExtensions.cs 2011-05-22 13:28:51 UTC (rev 5852) @@ -24,15 +24,376 @@ /// Project SQL function year() /// Note: throws an exception outside of a QueryOver expression /// </summary> - public static int Year(this DateTime dateTimeProperty) + public static int YearPart(this DateTime dateTimeProperty) { throw new Exception("Not to be used directly - use inside QueryOver expression"); } - internal static IProjection ProcessYear(MethodCallExpression methodCallExpression) + internal static IProjection ProcessYearPart(MethodCallExpression methodCallExpression) { IProjection property = ExpressionProcessor.FindMemberProjection(methodCallExpression.Arguments[0]); return Projections.SqlFunction("year", NHibernateUtil.DateTime, property); } + + /// <summary> + /// Project SQL function day() + /// Note: throws an exception outside of a QueryOver expression + /// </summary> + public static int DayPart(this DateTime dateTimeProperty) + { + throw new Exception("Not to be used directly - use inside QueryOver expression"); + } + + internal static IProjection ProcessDayPart(MethodCallExpression methodCallExpression) + { + IProjection property = ExpressionProcessor.FindMemberProjection(methodCallExpression.Arguments[0]); + return Projections.SqlFunction("day", NHibernateUtil.DateTime, property); + } + + /// <summary> + /// Project SQL function month() + /// Note: throws an exception outside of a QueryOver expression + /// </summary> + public static int MonthPart(this DateTime dateTimeProperty) + { + throw new Exception("Not to be used directly - use inside QueryOver expression"); + } + + internal static IProjection ProcessMonthPart(MethodCallExpression methodCallExpression) + { + IProjection property = ExpressionProcessor.FindMemberProjection(methodCallExpression.Arguments[0]); + return Projections.SqlFunction("month", NHibernateUtil.DateTime, property); + } + + /// <summary> + /// Project SQL function hour() + /// Note: throws an exception outside of a QueryOver expression + /// </summary> + public static int HourPart(this DateTime dateTimeProperty) + { + throw new Exception("Not to be used directly - use inside QueryOver expression"); + } + + internal static IProjection ProcessHourPart(MethodCallExpression methodCallExpression) + { + IProjection property = ExpressionProcessor.FindMemberProjection(methodCallExpression.Arguments[0]); + return Projections.SqlFunction("hour", NHibernateUtil.DateTime, property); + } + + /// <summary> + /// Project SQL function minute() + /// Note: throws an exception outside of a QueryOver expression + /// </summary> + public static int MinutePart(this DateTime dateTimeProperty) + { + throw new Exception("Not to be used directly - use inside QueryOver expression"); + } + + internal static IProjection ProcessMinutePart(MethodCallExpression methodCallExpression) + { + IProjection property = ExpressionProcessor.FindMemberProjection(methodCallExpression.Arguments[0]); + return Projections.SqlFunction("minute", NHibernateUtil.DateTime, property); + } + + /// <summary> + /// Project SQL function second() + /// Note: throws an exception outside of a QueryOver expression + /// </summary> + public static int SecondPart(this DateTime dateTimeProperty) + { + throw new Exception("Not to be used directly - use inside QueryOver expression"); + } + + internal static IProjection ProcessSecondPart(MethodCallExpression methodCallExpression) + { + IProjection property = ExpressionProcessor.FindMemberProjection(methodCallExpression.Arguments[0]); + return Projections.SqlFunction("second", NHibernateUtil.DateTime, property); + } + + /// <summary> + /// Project SQL function sqrt() + /// Note: throws an exception outside of a QueryOver expression + /// </summary> + public static double Sqrt(this double numericProperty) + { + 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) + { + 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) + { + 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) + { + 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) + { + throw new Exception("Not to be used directly - use inside QueryOver expression"); + } + + internal static IProjection ProcessByteSqrt(MethodCallExpression methodCallExpression) + { + IProjection property = ExpressionProcessor.FindMemberProjection(methodCallExpression.Arguments[0]); + return Projections.SqlFunction("sqrt", NHibernateUtil.Byte, property); + } + + /// <summary> + /// Project SQL function lower() + /// Note: throws an exception outside of a QueryOver expression + /// </summary> + public static string Lower(this string stringProperty) + { + throw new Exception("Not to be used directly - use inside QueryOver expression"); + } + + internal static IProjection ProcessLower(MethodCallExpression methodCallExpression) + { + IProjection property = ExpressionProcessor.FindMemberProjection(methodCallExpression.Arguments[0]); + return Projections.SqlFunction("lower", NHibernateUtil.String, property); + } + + /// <summary> + /// Project SQL function upper() + /// Note: throws an exception outside of a QueryOver expression + /// </summary> + public static string Upper(this string stringProperty) + { + throw new Exception("Not to be used directly - use inside QueryOver expression"); + } + + internal static IProjection ProcessUpper(MethodCallExpression methodCallExpression) + { + IProjection property = ExpressionProcessor.FindMemberProjection(methodCallExpression.Arguments[0]); + return Projections.SqlFunction("upper", NHibernateUtil.String, property); + } + + /// <summary> + /// Project SQL function abs() + /// Note: throws an exception outside of a QueryOver expression + /// </summary> + public static int Abs(this int numericProperty) + { + throw new Exception("Not to be used directly - use inside QueryOver expression"); + } + + internal static IProjection ProcessIntAbs(MethodCallExpression methodCallExpression) + { + IProjection property = ExpressionProcessor.FindMemberProjection(methodCallExpression.Arguments[0]); + return Projections.SqlFunction("abs", NHibernateUtil.Int32, property); + } + + /// <summary> + /// Project SQL function abs() + /// Note: throws an exception outside of a QueryOver expression + /// </summary> + public static Int64 Abs(this Int64 numericProperty) + { + throw new Exception("Not to be used directly - use inside QueryOver expression"); + } + + internal static IProjection ProcessInt64Abs(MethodCallExpression methodCallExpression) + { + IProjection property = ExpressionProcessor.FindMemberProjection(methodCallExpression.Arguments[0]); + return Projections.SqlFunction("abs", NHibernateUtil.Int64, property); + } + + /// <summary> + /// Project SQL function abs() + /// Note: throws an exception outside of a QueryOver expression + /// </summary> + public static double Abs(this double numericProperty) + { + throw new Exception("Not to be used directly - use inside QueryOver expression"); + } + + internal static IProjection ProcessDoubleAbs(MethodCallExpression methodCallExpression) + { + IProjection property = ExpressionProcessor.FindMemberProjection(methodCallExpression.Arguments[0]); + return Projections.SqlFunction("abs", NHibernateUtil.Double, property); + } + + /// <summary> + /// Project SQL function trim() + /// Note: throws an exception outside of a QueryOver expression + /// </summary> + public static string TrimStr(this string stringProperty) + { + throw new Exception("Not to be used directly - use inside QueryOver expression"); + } + + internal static IProjection ProcessTrimStr(MethodCallExpression methodCallExpression) + { + IProjection property = ExpressionProcessor.FindMemberProjection(methodCallExpression.Arguments[0]); + return Projections.SqlFunction("trim", NHibernateUtil.String, property); + } + + /// <summary> + /// Project SQL function length() + /// Note: throws an exception outside of a QueryOver expression + /// </summary> + public static int StrLength(this string stringProperty) + { + throw new Exception("Not to be used directly - use inside QueryOver expression"); + } + + internal static IProjection ProcessStrLength(MethodCallExpression methodCallExpression) + { + IProjection property = ExpressionProcessor.FindMemberProjection(methodCallExpression.Arguments[0]); + return Projections.SqlFunction("length", NHibernateUtil.String, property); + } + + /// <summary> + /// Project SQL function bit_length() + /// Note: throws an exception outside of a QueryOver expression + /// </summary> + public static int BitLength(this string stringProperty) + { + throw new Exception("Not to be used directly - use inside QueryOver expression"); + } + + internal static IProjection ProcessBitLength(MethodCallExpression methodCallExpression) + { + IProjection property = ExpressionProcessor.FindMemberProjection(methodCallExpression.Arguments[0]); + return Projections.SqlFunction("bit_length", NHibernateUtil.String, property); + } + + /// <summary> + /// Project SQL function substring() + /// Note: throws an exception outside of a QueryOver expression + /// </summary> + public static string Substr(this string stringProperty, int startIndex, int length) + { + throw new Exception("Not to be used directly - use inside QueryOver expression"); + } + + internal static IProjection ProcessSubstr(MethodCallExpression methodCallExpression) + { + IProjection property = ExpressionProcessor.FindMemberProjection(methodCallExpression.Arguments[0]); + object startIndex = ExpressionProcessor.FindValue(methodCallExpression.Arguments[1]); + object length = ExpressionProcessor.FindValue(methodCallExpression.Arguments[2]); + return Projections.SqlFunction("substring", NHibernateUtil.String, property, Projections.Constant(startIndex), Projections.Constant(length)); + } + + /// <summary> + /// Project SQL function locate() + /// Note: throws an exception outside of a QueryOver expression + /// </summary> + public static int CharIndex(this string stringProperty, string theChar, int startLocation) + { + throw new Exception("Not to be used directly - use inside QueryOver expression"); + } + + internal static IProjection ProcessCharIndex(MethodCallExpression methodCallExpression) + { + IProjection property = ExpressionProcessor.FindMemberProjection(methodCallExpression.Arguments[0]); + object theChar = ExpressionProcessor.FindValue(methodCallExpression.Arguments[1]); + object startLocation = ExpressionProcessor.FindValue(methodCallExpression.Arguments[2]); + return Projections.SqlFunction("locate", NHibernateUtil.String, Projections.Constant(theChar), property, Projections.Constant(startLocation)); + } + + /// <summary> + /// Project SQL function coalesce() + /// Note: throws an exception outside of a QueryOver expression + /// </summary> + public static T Coalesce<T>(this T objectProperty, T replaceValueIfIsNull) + { + throw new Exception("Not to be used directly - use inside QueryOver expression"); + } + + /// <summary> + /// Project SQL function coalesce() + /// Note: throws an exception outside of a QueryOver expression + /// </summary> + public static Nullable<T> Coalesce<T>(this Nullable<T> objectProperty, T replaceValueIfIsNull) where T : struct + { + throw new Exception("Not to be used directly - use inside QueryOver expression"); + } + + internal static IProjection ProcessCoalesce(MethodCallExpression methodCallExpression) + { + IProjection property = ExpressionProcessor.FindMemberProjection(methodCallExpression.Arguments[0]); + object replaceValueIfIsNull = ExpressionProcessor.FindValue(methodCallExpression.Arguments[1]); + return Projections.SqlFunction("coalesce", NHibernateUtil.Object, property, Projections.Constant(replaceValueIfIsNull)); + } + + /// <summary> + /// Project SQL function concat() + /// Note: throws an exception outside of a QueryOver expression + /// </summary> + public static string ConcatStr(this string stringProperty, string value) + { + throw new Exception("Not to be used directly - use inside QueryOver expression"); + } + + internal static IProjection ProcessConcatStr(MethodCallExpression methodCallExpression) + { + IProjection property = ExpressionProcessor.FindMemberProjection(methodCallExpression.Arguments[0]); + object concatWithValue = ExpressionProcessor.FindValue(methodCallExpression.Arguments[1]); + return Projections.SqlFunction("concat", NHibernateUtil.String, property, Projections.Constant(string.Empty), Projections.Constant(concatWithValue)); + } + + /// <summary> + /// Project SQL function mod() + /// Note: throws an exception outside of a QueryOver expression + /// </summary> + public static int Mod(this int numericProperty, int divisor) + { + throw new Exception("Not to be used directly - use inside QueryOver expression"); + } + + internal static IProjection ProcessMod(MethodCallExpression methodCallExpression) + { + IProjection property = ExpressionProcessor.FindMemberProjection(methodCallExpression.Arguments[0]); + object divisor = ExpressionProcessor.FindValue(methodCallExpression.Arguments[1]); + return Projections.SqlFunction("mod", NHibernateUtil.Int32, property, Projections.Constant(divisor)); + } } } Modified: trunk/nhibernate/src/NHibernate/Impl/ExpressionProcessor.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Impl/ExpressionProcessor.cs 2011-05-22 11:02:26 UTC (rev 5851) +++ trunk/nhibernate/src/NHibernate/Impl/ExpressionProcessor.cs 2011-05-22 13:28:51 UTC (rev 5852) @@ -89,7 +89,31 @@ RegisterCustomMethodCall(() => RestrictionExtensions.IsBetween(null, null).And(null), RestrictionExtensions.ProcessIsBetween); _customProjectionProcessors = new Dictionary<string, Func<MethodCallExpression, IProjection>>(); - RegisterCustomProjection(() => ProjectionsExtensions.Year(default(DateTime)), ProjectionsExtensions.ProcessYear); + RegisterCustomProjection(() => ProjectionsExtensions.YearPart(default(DateTime)), ProjectionsExtensions.ProcessYearPart); + RegisterCustomProjection(() => ProjectionsExtensions.DayPart(default(DateTime)), ProjectionsExtensions.ProcessDayPart); + RegisterCustomProjection(() => ProjectionsExtensions.MonthPart(default(DateTime)), ProjectionsExtensions.ProcessMonthPart); + 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.Lower(string.Empty), ProjectionsExtensions.ProcessLower); + RegisterCustomProjection(() => ProjectionsExtensions.Upper(string.Empty), ProjectionsExtensions.ProcessUpper); + RegisterCustomProjection(() => ProjectionsExtensions.TrimStr(string.Empty), ProjectionsExtensions.ProcessTrimStr); + RegisterCustomProjection(() => ProjectionsExtensions.StrLength(string.Empty), ProjectionsExtensions.ProcessStrLength); + RegisterCustomProjection(() => ProjectionsExtensions.BitLength(string.Empty), ProjectionsExtensions.ProcessBitLength); + RegisterCustomProjection(() => ProjectionsExtensions.Substr(string.Empty, 0, 0), ProjectionsExtensions.ProcessSubstr); + RegisterCustomProjection(() => ProjectionsExtensions.CharIndex(string.Empty, string.Empty, 0), ProjectionsExtensions.ProcessCharIndex); + RegisterCustomProjection(() => ProjectionsExtensions.Coalesce<DBNull>(null, null), ProjectionsExtensions.ProcessCoalesce); + RegisterCustomProjection(() => ProjectionsExtensions.Coalesce<int>(null, 0), ProjectionsExtensions.ProcessCoalesce); + RegisterCustomProjection(() => ProjectionsExtensions.ConcatStr(string.Empty, string.Empty), ProjectionsExtensions.ProcessConcatStr); + RegisterCustomProjection(() => ProjectionsExtensions.Mod(0, 0), ProjectionsExtensions.ProcessMod); + RegisterCustomProjection(() => ProjectionsExtensions.Abs(default(int)), ProjectionsExtensions.ProcessIntAbs); + RegisterCustomProjection(() => ProjectionsExtensions.Abs(default(double)), ProjectionsExtensions.ProcessDoubleAbs); + RegisterCustomProjection(() => ProjectionsExtensions.Abs(default(Int64)), ProjectionsExtensions.ProcessInt64Abs); } private static ICriterion Eq(IProjection propertyName, object value) @@ -204,7 +228,7 @@ if (methodCallExpression.Method.Name == "First") return FindMemberExpression(methodCallExpression.Arguments[0]); - throw new Exception("Unrecognised method call in epression " + expression.ToString()); + throw new Exception("Unrecognised method call in expression " + expression.ToString()); } throw new Exception("Could not determine member from " + expression.ToString()); @@ -484,8 +508,11 @@ return "class"; } - private static string Signature(MethodInfo methodInfo) + public static string Signature(MethodInfo methodInfo) { + while (methodInfo.IsGenericMethod && !methodInfo.IsGenericMethodDefinition) + methodInfo = methodInfo.GetGenericMethodDefinition(); + return methodInfo.DeclaringType.FullName + ":" + methodInfo.ToString(); } Modified: trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/ExpressionProcessorFixture.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/ExpressionProcessorFixture.cs 2011-05-22 11:02:26 UTC (rev 5851) +++ trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/ExpressionProcessorFixture.cs 2011-05-22 13:28:51 UTC (rev 5852) @@ -2,11 +2,11 @@ using System; using System.Linq; using System.Linq.Expressions; - +using System.Reflection; using NHibernate.Criterion; using NHibernate.Impl; - using NUnit.Framework; +using SharpTestsEx; namespace NHibernate.Test.Criteria.Lambda { @@ -155,6 +155,34 @@ Assert.AreEqual(before.ToString(), after.ToString()); } + public void NonGenericMethod(string param1) { } + public T GenericMethod<T>(T param1) { return param1; } + + [Test] + public void TestSignatureNonGeneric() + { + MethodInfo thisMethod = GetType().GetMethod("NonGenericMethod"); + + ExpressionProcessor.Signature(thisMethod).Should().Be("NHibernate.Test.Criteria.Lambda.ExpressionProcessorFixture:Void NonGenericMethod(System.String)"); + } + + [Test] + public void TestSignatureGeneric() + { + MethodInfo thisMethod = GetType().GetMethod("GenericMethod"); + + ExpressionProcessor.Signature(thisMethod).Should().Be("NHibernate.Test.Criteria.Lambda.ExpressionProcessorFixture:T GenericMethod[T](T)"); + } + + [Test] + public void TestSignatureQualifiedGeneric() + { + Expression<Func<string>> expression = () => this.GenericMethod("test"); + MethodInfo genericMethodWithQualifiedType = (expression.Body as MethodCallExpression).Method; + + ExpressionProcessor.Signature(genericMethodWithQualifiedType).Should().Be("NHibernate.Test.Criteria.Lambda.ExpressionProcessorFixture:T GenericMethod[T](T)"); + } + } } Modified: trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/IntegrationFixture.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/IntegrationFixture.cs 2011-05-22 11:02:26 UTC (rev 5851) +++ trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/IntegrationFixture.cs 2011-05-22 13:28:51 UTC (rev 5852) @@ -584,7 +584,7 @@ { var persons = s.QueryOver<Person>() - .Where(p => p.BirthDate.Year() == 2008) + .Where(p => p.BirthDate.YearPart() == 2008) .List(); persons.Count.Should().Be(1); Modified: trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/RestrictionsFixture.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/RestrictionsFixture.cs 2011-05-22 11:02:26 UTC (rev 5851) +++ trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/RestrictionsFixture.cs 2011-05-22 13:28:51 UTC (rev 5852) @@ -260,11 +260,47 @@ { ICriteria expected = CreateTestCriteria(typeof(Person)) - .Add(Restrictions.Eq(Projections.SqlFunction("year", NHibernateUtil.DateTime, Projections.Property("BirthDate")), 1970)); + .Add(Restrictions.Eq(Projections.SqlFunction("year", NHibernateUtil.DateTime, Projections.Property("BirthDate")), 1970)) + .Add(Restrictions.Eq(Projections.SqlFunction("day", NHibernateUtil.DateTime, Projections.Property("BirthDate")), 1)) + .Add(Restrictions.Eq(Projections.SqlFunction("month", NHibernateUtil.DateTime, Projections.Property("BirthDate")), 1)) + .Add(Restrictions.Eq(Projections.SqlFunction("hour", NHibernateUtil.DateTime, Projections.Property("BirthDate")), 1)) + .Add(Restrictions.Eq(Projections.SqlFunction("minute", NHibernateUtil.DateTime, Projections.Property("BirthDate")), 1)) + .Add(Restrictions.Eq(Projections.SqlFunction("second", NHibernateUtil.DateTime, Projections.Property("BirthDate")), 1)) + .Add(Restrictions.Eq(Projections.SqlFunction("sqrt", NHibernateUtil.Int32, Projections.Property("Height")), 10)) + .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)) + .Add(Restrictions.Eq(Projections.SqlFunction("trim", NHibernateUtil.String, Projections.Property("Name")), "test")) + .Add(Restrictions.Eq(Projections.SqlFunction("length", NHibernateUtil.String, Projections.Property("Name")), 4)) + .Add(Restrictions.Eq(Projections.SqlFunction("bit_length", NHibernateUtil.String, Projections.Property("Name")), 32)) + .Add(Restrictions.Eq(Projections.SqlFunction("substring", NHibernateUtil.String, Projections.Property("Name"), Projections.Constant(1), Projections.Constant(2)), "te")) + .Add(Restrictions.Eq(Projections.SqlFunction("locate", NHibernateUtil.String, Projections.Constant("e"), Projections.Property("Name"), Projections.Constant(1)), 2)) + .Add(Restrictions.Eq(Projections.SqlFunction("coalesce", NHibernateUtil.Object, Projections.Property("Name"), Projections.Constant("not-null-val")), "test")) + .Add(Restrictions.Eq(Projections.SqlFunction("coalesce", NHibernateUtil.Object, Projections.Property("NullableIsParent"), Projections.Constant(true)), true)) + .Add(Restrictions.Eq(Projections.SqlFunction("concat", NHibernateUtil.String, Projections.Property("Name"), Projections.Constant(string.Empty), Projections.Constant("A")), "testA")) + .Add(Restrictions.Eq(Projections.SqlFunction("mod", NHibernateUtil.Int32, Projections.Property("Height"), Projections.Constant(10)), 0)); IQueryOver<Person> actual = CreateTestQueryOver<Person>() - .Where(p => p.BirthDate.Year() == 1970); + .Where(p => p.BirthDate.YearPart() == 1970) + .And(p => p.BirthDate.DayPart() == 1) + .And(p => p.BirthDate.MonthPart() == 1) + .And(p => p.BirthDate.HourPart() == 1) + .And(p => p.BirthDate.MinutePart() == 1) + .And(p => p.BirthDate.SecondPart() == 1) + .And(p => p.Height.Sqrt() == 10) + .And(p => p.Name.Lower() == "test") + .And(p => p.Name.Upper() == "TEST") + .And(p => p.Height.Abs() == 150) + .And(p => p.Name.TrimStr() == "test") + .And(p => p.Name.StrLength() == 4) + .And(p => p.Name.BitLength() == 32) + .And(p => p.Name.Substr(1, 2) == "te") + .And(p => p.Name.CharIndex("e", 1) == 2) + .And(p => p.Name.Coalesce("not-null-val") == "test") + .And(p => p.NullableIsParent.Coalesce(true) == true) + .And(p => p.Name.ConcatStr("A") == "testA") + .And(p => p.Height.Mod(10) == 0); AssertCriteriaAreEqual(expected, actual); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |