|
From: <Ric...@us...> - 2009-06-28 21:59:30
|
Revision: 4541
http://nhibernate.svn.sourceforge.net/nhibernate/?rev=4541&view=rev
Author: RicBrown
Date: 2009-06-28 21:59:29 +0000 (Sun, 28 Jun 2009)
Log Message:
-----------
Added creation of sub-criteria to ICriteria<T>.
Modified Paths:
--------------
trunk/nhibernate/src/NHibernate/ICriteriaOfT.cs
trunk/nhibernate/src/NHibernate/Impl/CriteriaOfTImpl.cs
trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/CriteriaOfTFixture.cs
trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/Model.cs
Modified: trunk/nhibernate/src/NHibernate/ICriteriaOfT.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/ICriteriaOfT.cs 2009-06-28 13:57:21 UTC (rev 4540)
+++ trunk/nhibernate/src/NHibernate/ICriteriaOfT.cs 2009-06-28 21:59:29 UTC (rev 4541)
@@ -12,10 +12,10 @@
/// </summary>
/// <remarks>
/// <code>
- /// IList<Cat> cats = session.QueryOver<Cat>()
- /// .Add( c => c.Name == "Tigger" )
- /// .Add( c => c.Weight > minWeight ) )
- /// .List();
+ /// IList<Cat> cats = session.QueryOver<Cat>()
+ /// .Add( c => c.Name == "Tigger" )
+ /// .Add( c => c.Weight > minWeight ) )
+ /// .List();
/// </code>
/// </remarks>
public interface ICriteria<T>
@@ -50,6 +50,23 @@
ICriteria<T> Where(Expression<Func<bool>> expression);
/// <summary>
+ /// Creates a new NHibernate.ICriteria<T>, "rooted" at the associated entity
+ /// </summary>
+ /// <typeparam name="U">Type of sub-criteria</typeparam>
+ /// <param name="expression">Lambda expression returning association path</param>
+ /// <returns>The created "sub criteria"</returns>
+ ICriteria<U> Join<U>(Expression<Func<T, U>> expression);
+
+ /// <summary>
+ /// Creates a new NHibernate.ICriteria<T>, "rooted" at the associated entity
+ /// specifying a collection for the join.
+ /// </summary>
+ /// <typeparam name="U">Type of sub-criteria (type of the collection)</typeparam>
+ /// <param name="expression">Lambda expression returning association path</param>
+ /// <returns>The created "sub criteria"</returns>
+ ICriteria<U> Join<U>(Expression<Func<T, IEnumerable<U>>> expression);
+
+ /// <summary>
/// Get the results of the root type and fill the <see cref="IList<T>"/>
/// </summary>
/// <param name="results">The list filled with the results.</param>
Modified: trunk/nhibernate/src/NHibernate/Impl/CriteriaOfTImpl.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Impl/CriteriaOfTImpl.cs 2009-06-28 13:57:21 UTC (rev 4540)
+++ trunk/nhibernate/src/NHibernate/Impl/CriteriaOfTImpl.cs 2009-06-28 21:59:29 UTC (rev 4541)
@@ -45,6 +45,20 @@
return Add(expression);
}
+ ICriteria<U> ICriteria<T>.Join<U>(Expression<Func<T, U>> expression)
+ {
+ return new CriteriaImpl<U>(
+ _criteria.CreateCriteria(
+ ExpressionProcessor.FindMemberExpression(expression.Body)));
+ }
+
+ ICriteria<U> ICriteria<T>.Join<U>(Expression<Func<T, IEnumerable<U>>> expression)
+ {
+ return new CriteriaImpl<U>(
+ _criteria.CreateCriteria(
+ ExpressionProcessor.FindMemberExpression(expression.Body)));
+ }
+
IList<T> ICriteria<T>.List()
{
return _criteria.List<T>();
Modified: trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/CriteriaOfTFixture.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/CriteriaOfTFixture.cs 2009-06-28 13:57:21 UTC (rev 4540)
+++ trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/CriteriaOfTFixture.cs 2009-06-28 21:59:29 UTC (rev 4541)
@@ -61,6 +61,38 @@
AssertCriteriaAreEqual(expected, actual);
}
+ [Test]
+ public void SubCriteria_Join_ToOne()
+ {
+ ICriteria expected =
+ CreateTestCriteria(typeof(Person))
+ .CreateCriteria("Father")
+ .Add(Expression.Eq("Name", "test name"));
+
+ ICriteria<Person> actual =
+ CreateTestQueryOver<Person>()
+ .Join(p => p.Father) // sub-criteria
+ .Where(f => f.Name == "test name");
+
+ AssertCriteriaAreEqual(expected, actual);
+ }
+
+ [Test]
+ public void SubCriteria_Join_ToMany()
+ {
+ ICriteria expected =
+ CreateTestCriteria(typeof(Person))
+ .CreateCriteria("Children")
+ .Add(Expression.Eq("Nickname", "test name"));
+
+ ICriteria<Child> actual =
+ CreateTestQueryOver<Person>()
+ .Join<Child>(p => p.Children) // sub-criteria
+ .Where(c => c.Nickname == "test name");
+
+ AssertCriteriaAreEqual(expected, actual);
+ }
+
}
}
\ No newline at end of file
Modified: trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/Model.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/Model.cs 2009-06-28 13:57:21 UTC (rev 4540)
+++ trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/Model.cs 2009-06-28 21:59:29 UTC (rev 4541)
@@ -7,14 +7,18 @@
public class Person
{
- public virtual int Id { get; set; }
- public virtual string Name { get; set; }
- public virtual int Age { get; set; }
+ public virtual int Id { get; set; }
+ public virtual string Name { get; set; }
+ public virtual int Age { get; set; }
+ public virtual Person Father { get; set; }
+
+ public virtual IEnumerable<Child> Children { get; set; }
}
public class Child
{
- public virtual int Id { get; set; }
+ public virtual int Id { get; set; }
+ public virtual string Nickname { get; set; }
}
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|