|
From: <ric...@us...> - 2009-07-08 09:44:29
|
Revision: 4590
http://nhibernate.svn.sourceforge.net/nhibernate/?rev=4590&view=rev
Author: ricbrown
Date: 2009-07-08 09:44:23 +0000 (Wed, 08 Jul 2009)
Log Message:
-----------
Added place-holder for QueryOver join syntax.
Modified Paths:
--------------
trunk/nhibernate/src/NHibernate/Criterion/QueryOver.cs
trunk/nhibernate/src/NHibernate/IQueryOver.cs
trunk/nhibernate/src/NHibernate/NHibernate.csproj
trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/QueryOverFixture.cs
Added Paths:
-----------
trunk/nhibernate/src/NHibernate/Criterion/QueryOverJoinBuilder.cs
Modified: trunk/nhibernate/src/NHibernate/Criterion/QueryOver.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Criterion/QueryOver.cs 2009-07-06 08:48:13 UTC (rev 4589)
+++ trunk/nhibernate/src/NHibernate/Criterion/QueryOver.cs 2009-07-08 09:44:23 UTC (rev 4590)
@@ -104,6 +104,19 @@
JoinType.InnerJoin);
}
+ public QueryOver<T> Join(Expression<Func<T, object>> path, Expression<Func<object>> alias, JoinType joinType)
+ {
+ return AddAlias(
+ ExpressionProcessor.FindMemberExpression(path.Body),
+ ExpressionProcessor.FindMemberExpression(alias.Body),
+ joinType);
+ }
+
+ public QueryOverJoinBuilder<T> Inner
+ {
+ get { return new QueryOverJoinBuilder<T>(this, JoinType.InnerJoin); }
+ }
+
public IList<T> List()
{
return _criteria.List<T>();
@@ -182,6 +195,12 @@
IQueryOver<T> IQueryOver<T>.Join(Expression<Func<T, object>> path, Expression<Func<object>> alias)
{ return Join(path, alias); }
+ IQueryOver<T> IQueryOver<T>.Join(Expression<Func<T, object>> path, Expression<Func<object>> alias, JoinType joinType)
+ { return Join(path, alias, joinType); }
+
+ IQueryOverJoinBuilder<T> IQueryOver<T>.Left
+ { get { return new IQueryOverJoinBuilder<T>(this, JoinType.LeftOuterJoin); } }
+
}
}
Added: trunk/nhibernate/src/NHibernate/Criterion/QueryOverJoinBuilder.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Criterion/QueryOverJoinBuilder.cs (rev 0)
+++ trunk/nhibernate/src/NHibernate/Criterion/QueryOverJoinBuilder.cs 2009-07-08 09:44:23 UTC (rev 4590)
@@ -0,0 +1,41 @@
+
+using System;
+using System.Collections.Generic;
+using System.Linq.Expressions;
+
+using NHibernate.Impl;
+using NHibernate.SqlCommand;
+
+namespace NHibernate.Criterion
+{
+
+ public class QueryOverJoinBuilder<T> : QueryOverJoinBuilderBase<QueryOver<T>, T>
+ {
+ public QueryOverJoinBuilder(QueryOver<T> root, JoinType joinType) : base(root, joinType) { }
+ }
+
+ public class IQueryOverJoinBuilder<T> : QueryOverJoinBuilderBase<IQueryOver<T>, T>
+ {
+ public IQueryOverJoinBuilder(IQueryOver<T> root, JoinType joinType) : base(root, joinType) { }
+ }
+
+ public class QueryOverJoinBuilderBase<R, T> where R : IQueryOver<T>
+ {
+
+ private R _root;
+ private JoinType _joinType;
+
+ public QueryOverJoinBuilderBase(R root, JoinType joinType)
+ {
+ _root = root;
+ _joinType = joinType;
+ }
+
+ public R Join(Expression<Func<T, object>> path, Expression<Func<object>> alias)
+ {
+ return (R)_root.Join(path, alias, _joinType);
+ }
+
+ }
+
+}
Modified: trunk/nhibernate/src/NHibernate/IQueryOver.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/IQueryOver.cs 2009-07-06 08:48:13 UTC (rev 4589)
+++ trunk/nhibernate/src/NHibernate/IQueryOver.cs 2009-07-08 09:44:23 UTC (rev 4590)
@@ -4,6 +4,7 @@
using System.Linq.Expressions;
using NHibernate.Criterion;
+using NHibernate.SqlCommand;
namespace NHibernate
{
@@ -113,6 +114,16 @@
IQueryOver<T> Join(Expression<Func<T, object>> path, Expression<Func<object>> alias);
/// <summary>
+ /// Join an association, assigning an alias to the joined entity
+ /// </summary>
+ /// <param name="path">Lambda expression returning association path</param>
+ /// <param name="alias">Lambda expression returning alias reference</param>
+ /// <returns>criteria instance</returns>
+ IQueryOver<T> Join(Expression<Func<T, object>> path, Expression<Func<object>> alias, JoinType joinType);
+
+ IQueryOverJoinBuilder<T> Left { get; }
+
+ /// <summary>
/// Get the results of the root type and fill the <see cref="IList<T>"/>
/// </summary>
/// <returns>The list filled with the results.</returns>
Modified: trunk/nhibernate/src/NHibernate/NHibernate.csproj
===================================================================
--- trunk/nhibernate/src/NHibernate/NHibernate.csproj 2009-07-06 08:48:13 UTC (rev 4589)
+++ trunk/nhibernate/src/NHibernate/NHibernate.csproj 2009-07-08 09:44:23 UTC (rev 4590)
@@ -486,6 +486,7 @@
<Compile Include="Cfg\MappingSchema\HbmVersion.cs" />
<Compile Include="Cfg\MappingSchema\IDecoratable.cs" />
<Compile Include="Criterion\IPropertyProjection.cs" />
+ <Compile Include="Criterion\QueryOverJoinBuilder.cs" />
<Compile Include="Dialect\MsSql2008Dialect.cs" />
<Compile Include="Dialect\InformixDialect0940.cs" />
<Compile Include="Dialect\InformixDialect1000.cs" />
Modified: trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/QueryOverFixture.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/QueryOverFixture.cs 2009-07-06 08:48:13 UTC (rev 4589)
+++ trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/QueryOverFixture.cs 2009-07-08 09:44:23 UTC (rev 4590)
@@ -4,6 +4,7 @@
using NUnit.Framework;
using NHibernate.Criterion;
+using NHibernate.SqlCommand;
using NHibernate.Transform;
using NHibernate.Type;
using NHibernate.Util;
@@ -128,7 +129,7 @@
}
[Test]
- public void SubCriteria_JoinWalk_ToOne()
+ public void SubCriteria_JoinQueryOver_ToOne()
{
ICriteria expected =
CreateTestCriteria(typeof(Person))
@@ -144,7 +145,7 @@
}
[Test]
- public void SubCriteria_JoinWalk_ToMany()
+ public void SubCriteria_JoinQueryOver_ToMany()
{
ICriteria expected =
CreateTestCriteria(typeof(Person))
@@ -178,6 +179,24 @@
}
[Test]
+ public void Alias_LeftJoin()
+ {
+ ICriteria expected =
+ CreateTestCriteria(typeof(Person))
+ .CreateAlias("Father", "fatherAlias", JoinType.LeftOuterJoin)
+ .CreateAlias("Children", "childAlias", JoinType.LeftOuterJoin);
+
+ Person fatherAlias = null;
+ Child childAlias = null;
+ IQueryOver<Person> actual =
+ CreateTestQueryOver<Person>()
+ .Left.Join(p => p.Father, () => fatherAlias)
+ .Left.Join(p => p.Children, () => childAlias);
+
+ AssertCriteriaAreEqual(expected, actual);
+ }
+
+ [Test]
public void OrderBy()
{
ICriteria expected =
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|