|
From: <ric...@us...> - 2010-07-08 22:14:00
|
Revision: 5003
http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5003&view=rev
Author: ricbrown
Date: 2010-07-08 22:13:54 +0000 (Thu, 08 Jul 2010)
Log Message:
-----------
Added extension methods for QueryOver builders to allow single-line statements on builders e.g., query.OrderBy(p => p.Name).Asc();
Modified Paths:
--------------
trunk/nhibernate/src/NHibernate/Criterion/Lambda/QueryOverFetchBuilder.cs
trunk/nhibernate/src/NHibernate/NHibernate.csproj
trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/QueryOverFixture.cs
Added Paths:
-----------
trunk/nhibernate/src/NHibernate/Criterion/QueryOverBuilderExtensions.cs
Modified: trunk/nhibernate/src/NHibernate/Criterion/Lambda/QueryOverFetchBuilder.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Criterion/Lambda/QueryOverFetchBuilder.cs 2010-07-08 20:48:39 UTC (rev 5002)
+++ trunk/nhibernate/src/NHibernate/Criterion/Lambda/QueryOverFetchBuilder.cs 2010-07-08 22:13:54 UTC (rev 5003)
@@ -6,7 +6,7 @@
using NHibernate.Impl;
using NHibernate.SqlCommand;
-namespace NHibernate.Criterion
+namespace NHibernate.Criterion.Lambda
{
public class QueryOverFetchBuilder<TRoot,TSubType> : QueryOverFetchBuilderBase<QueryOver<TRoot,TSubType>, TRoot, TSubType>
Added: trunk/nhibernate/src/NHibernate/Criterion/QueryOverBuilderExtensions.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Criterion/QueryOverBuilderExtensions.cs (rev 0)
+++ trunk/nhibernate/src/NHibernate/Criterion/QueryOverBuilderExtensions.cs 2010-07-08 22:13:54 UTC (rev 5003)
@@ -0,0 +1,168 @@
+using System;
+using System.Linq.Expressions;
+
+using NHibernate.Impl;
+
+namespace NHibernate.Criterion
+{
+ public static class QueryOverBuilderExtensions
+ {
+ // Fetch builder
+ public static QueryOver<TRoot, TSubType> Default<TRoot, TSubType>(this Lambda.QueryOverFetchBuilder<TRoot, TSubType> builder)
+ {
+ return builder.Default;
+ }
+
+ public static QueryOver<TRoot, TSubType> Eager<TRoot, TSubType>(this Lambda.QueryOverFetchBuilder<TRoot, TSubType> builder)
+ {
+ return builder.Eager;
+ }
+
+ public static QueryOver<TRoot, TSubType> Lazy<TRoot, TSubType>(this Lambda.QueryOverFetchBuilder<TRoot, TSubType> builder)
+ {
+ return builder.Lazy;
+ }
+
+ public static IQueryOver<TRoot, TSubType> Default<TRoot, TSubType>(this Lambda.IQueryOverFetchBuilder<TRoot, TSubType> builder)
+ {
+ return builder.Default;
+ }
+
+ public static IQueryOver<TRoot, TSubType> Eager<TRoot, TSubType>(this Lambda.IQueryOverFetchBuilder<TRoot, TSubType> builder)
+ {
+ return builder.Eager;
+ }
+
+ public static IQueryOver<TRoot, TSubType> Lazy<TRoot, TSubType>(this Lambda.IQueryOverFetchBuilder<TRoot, TSubType> builder)
+ {
+ return builder.Lazy;
+ }
+
+
+ // Lock builder
+ public static QueryOver<TRoot, TSubType> Force<TRoot, TSubType>(this Lambda.QueryOverLockBuilder<TRoot, TSubType> builder)
+ {
+ return builder.Force;
+ }
+
+ public static QueryOver<TRoot, TSubType> None<TRoot, TSubType>(this Lambda.QueryOverLockBuilder<TRoot, TSubType> builder)
+ {
+ return builder.None;
+ }
+
+ public static QueryOver<TRoot, TSubType> Read<TRoot, TSubType>(this Lambda.QueryOverLockBuilder<TRoot, TSubType> builder)
+ {
+ return builder.Read;
+ }
+
+ public static QueryOver<TRoot, TSubType> Upgrade<TRoot, TSubType>(this Lambda.QueryOverLockBuilder<TRoot, TSubType> builder)
+ {
+ return builder.Upgrade;
+ }
+
+ public static QueryOver<TRoot, TSubType> UpgradeNoWait<TRoot, TSubType>(this Lambda.QueryOverLockBuilder<TRoot, TSubType> builder)
+ {
+ return builder.UpgradeNoWait;
+ }
+
+ public static QueryOver<TRoot, TSubType> Write<TRoot, TSubType>(this Lambda.QueryOverLockBuilder<TRoot, TSubType> builder)
+ {
+ return builder.Write;
+ }
+
+ public static IQueryOver<TRoot, TSubType> Force<TRoot, TSubType>(this Lambda.IQueryOverLockBuilder<TRoot, TSubType> builder)
+ {
+ return builder.Force;
+ }
+
+ public static IQueryOver<TRoot, TSubType> None<TRoot, TSubType>(this Lambda.IQueryOverLockBuilder<TRoot, TSubType> builder)
+ {
+ return builder.None;
+ }
+
+ public static IQueryOver<TRoot, TSubType> Read<TRoot, TSubType>(this Lambda.IQueryOverLockBuilder<TRoot, TSubType> builder)
+ {
+ return builder.Read;
+ }
+
+ public static IQueryOver<TRoot, TSubType> Upgrade<TRoot, TSubType>(this Lambda.IQueryOverLockBuilder<TRoot, TSubType> builder)
+ {
+ return builder.Upgrade;
+ }
+
+ public static IQueryOver<TRoot, TSubType> UpgradeNoWait<TRoot, TSubType>(this Lambda.IQueryOverLockBuilder<TRoot, TSubType> builder)
+ {
+ return builder.UpgradeNoWait;
+ }
+
+ public static IQueryOver<TRoot, TSubType> Write<TRoot, TSubType>(this Lambda.IQueryOverLockBuilder<TRoot, TSubType> builder)
+ {
+ return builder.Write;
+ }
+
+
+ // Order builder
+ public static QueryOver<TRoot, TSubType> Asc<TRoot, TSubType>(this Lambda.QueryOverOrderBuilder<TRoot, TSubType> builder)
+ {
+ return builder.Asc;
+ }
+
+ public static QueryOver<TRoot, TSubType> Desc<TRoot, TSubType>(this Lambda.QueryOverOrderBuilder<TRoot, TSubType> builder)
+ {
+ return builder.Desc;
+ }
+
+ public static IQueryOver<TRoot, TSubType> Asc<TRoot, TSubType>(this Lambda.IQueryOverOrderBuilder<TRoot, TSubType> builder)
+ {
+ return builder.Asc;
+ }
+
+ public static IQueryOver<TRoot, TSubType> Desc<TRoot, TSubType>(this Lambda.IQueryOverOrderBuilder<TRoot, TSubType> builder)
+ {
+ return builder.Desc;
+ }
+
+
+ // Restriction builder
+ public static QueryOver<TRoot, TSubType> IsEmpty<TRoot, TSubType>(this Lambda.QueryOverRestrictionBuilder<TRoot, TSubType> builder)
+ {
+ return builder.IsEmpty;
+ }
+
+ public static QueryOver<TRoot, TSubType> IsNotEmpty<TRoot, TSubType>(this Lambda.QueryOverRestrictionBuilder<TRoot, TSubType> builder)
+ {
+ return builder.IsNotEmpty;
+ }
+
+ public static QueryOver<TRoot, TSubType> IsNotNull<TRoot, TSubType>(this Lambda.QueryOverRestrictionBuilder<TRoot, TSubType> builder)
+ {
+ return builder.IsNotNull;
+ }
+
+ public static QueryOver<TRoot, TSubType> IsNull<TRoot, TSubType>(this Lambda.QueryOverRestrictionBuilder<TRoot, TSubType> builder)
+ {
+ return builder.IsNull;
+ }
+
+ public static IQueryOver<TRoot, TSubType> IsEmpty<TRoot, TSubType>(this Lambda.IQueryOverRestrictionBuilder<TRoot, TSubType> builder)
+ {
+ return builder.IsEmpty;
+ }
+
+ public static IQueryOver<TRoot, TSubType> IsNotEmpty<TRoot, TSubType>(this Lambda.IQueryOverRestrictionBuilder<TRoot, TSubType> builder)
+ {
+ return builder.IsNotEmpty;
+ }
+
+ public static IQueryOver<TRoot, TSubType> IsNotNull<TRoot, TSubType>(this Lambda.IQueryOverRestrictionBuilder<TRoot, TSubType> builder)
+ {
+ return builder.IsNotNull;
+ }
+
+ public static IQueryOver<TRoot, TSubType> IsNull<TRoot, TSubType>(this Lambda.IQueryOverRestrictionBuilder<TRoot, TSubType> builder)
+ {
+ return builder.IsNull;
+ }
+
+ }
+}
Modified: trunk/nhibernate/src/NHibernate/NHibernate.csproj
===================================================================
--- trunk/nhibernate/src/NHibernate/NHibernate.csproj 2010-07-08 20:48:39 UTC (rev 5002)
+++ trunk/nhibernate/src/NHibernate/NHibernate.csproj 2010-07-08 22:13:54 UTC (rev 5003)
@@ -1,4 +1,4 @@
-<?xml version="1.0" encoding="utf-8"?>
+<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="3.5">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
@@ -578,6 +578,7 @@
<Compile Include="Criterion\Lambda\QueryOverSubqueryBuilder.cs" />
<Compile Include="Criterion\Lambda\QueryOverSubqueryPropertyBuilder.cs" />
<Compile Include="Criterion\NullSubqueryExpression.cs" />
+ <Compile Include="Criterion\QueryOverBuilderExtensions.cs" />
<Compile Include="Criterion\ProjectionsExtensions.cs" />
<Compile Include="Dialect\MsSql2008Dialect.cs" />
<Compile Include="Dialect\InformixDialect0940.cs" />
Modified: trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/QueryOverFixture.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/QueryOverFixture.cs 2010-07-08 20:48:39 UTC (rev 5002)
+++ trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/QueryOverFixture.cs 2010-07-08 22:13:54 UTC (rev 5003)
@@ -373,6 +373,24 @@
}
[Test]
+ public void AllowSingleCallSyntax()
+ {
+ ICriteria expected = CreateTestCriteria(typeof(Person));
+ expected.Add(Restrictions.IsNotEmpty("Children"));
+ expected.AddOrder(Order.Asc("Name"));
+ expected.SetFetchMode("PersonList", FetchMode.Eager);
+ expected.SetLockMode(LockMode.UpgradeNoWait);
+
+ IQueryOver<Person,Person> actual = CreateTestQueryOver<Person>();
+ actual.WhereRestrictionOn(p => p.Children).IsNotEmpty();
+ actual.OrderBy(p => p.Name).Asc();
+ actual.Fetch(p => p.PersonList).Eager();
+ actual.Lock().UpgradeNoWait();
+
+ AssertCriteriaAreEqual(expected, actual);
+ }
+
+ [Test]
public void Project()
{
ICriteria expected =
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|