|
From: <Ric...@us...> - 2009-06-27 06:53:42
|
Revision: 4535
http://nhibernate.svn.sourceforge.net/nhibernate/?rev=4535&view=rev
Author: RicBrown
Date: 2009-06-27 06:53:39 +0000 (Sat, 27 Jun 2009)
Log Message:
-----------
Added first cut of ICriteria<T> alias syntax using a reference variable.
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/LambdaFixtureBase.cs
Modified: trunk/nhibernate/src/NHibernate/ICriteriaOfT.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/ICriteriaOfT.cs 2009-06-26 14:20:18 UTC (rev 4534)
+++ trunk/nhibernate/src/NHibernate/ICriteriaOfT.cs 2009-06-27 06:53:39 UTC (rev 4535)
@@ -36,6 +36,13 @@
ICriteria<T> Where(Expression<Func<T, bool>> expression);
/// <summary>
+ /// Add criterion expressed as a lambda expression
+ /// </summary>
+ /// <param name="expression">Lambda expression</param>
+ /// <returns>criteria instance</returns>
+ ICriteria<T> Where(Expression<Func<bool>> 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-26 14:20:18 UTC (rev 4534)
+++ trunk/nhibernate/src/NHibernate/Impl/CriteriaOfTImpl.cs 2009-06-27 06:53:39 UTC (rev 4535)
@@ -37,6 +37,12 @@
return this;
}
+ ICriteria<T> ICriteria<T>.Where(Expression<Func<bool>> expression)
+ {
+ _criteria.Add(ExpressionProcessor.ProcessExpression(expression));
+ return this;
+ }
+
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-26 14:20:18 UTC (rev 4534)
+++ trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/CriteriaOfTFixture.cs 2009-06-27 06:53:39 UTC (rev 4535)
@@ -16,19 +16,48 @@
{
[Test]
- public void Equality()
+ public void SimpleCriterion_NoAlias()
{
ICriteria expected =
CreateTestCriteria(typeof(Person))
.Add(Restrictions.Eq("Name", "test name"));
ICriteria<Person> actual =
- CreateTestCriteria<Person>()
+ CreateTestQueryOver<Person>()
.And(p => p.Name == "test name");
AssertCriteriaAreEqual(expected, actual);
}
+ [Test]
+ public void Where_BehavesTheSameAs_And()
+ {
+ Impl.CriteriaImpl<Person> expected = (Impl.CriteriaImpl<Person>)
+ CreateTestQueryOver<Person>()
+ .And(p => p.Name == "test name");
+
+ ICriteria<Person> actual =
+ CreateTestQueryOver<Person>()
+ .Where(p => p.Name == "test name");
+
+ AssertCriteriaAreEqual(expected.UnderlyingCriteria, actual);
+ }
+
+ [Test]
+ public void SimpleCriterion_AliasReferenceSyntax()
+ {
+ ICriteria expected =
+ CreateTestCriteria(typeof(Person), "personAlias")
+ .Add(Restrictions.Eq("personAlias.Name", "test name"));
+
+ Person personAlias = null;
+ ICriteria<Person> actual =
+ CreateTestQueryOver<Person>(() => personAlias)
+ .Where(() => personAlias.Name == "test name");
+
+ AssertCriteriaAreEqual(expected, actual);
+ }
+
}
}
\ No newline at end of file
Modified: trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/LambdaFixtureBase.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/LambdaFixtureBase.cs 2009-06-26 14:20:18 UTC (rev 4534)
+++ trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/LambdaFixtureBase.cs 2009-06-27 06:53:39 UTC (rev 4535)
@@ -3,6 +3,7 @@
using System.Collections;
using System.Collections.Generic;
using System.IO;
+using System.Linq.Expressions;
using System.Reflection;
using NHibernate.Criterion;
@@ -29,11 +30,17 @@
return new CriteriaImpl(persistentClass, alias, null);
}
- protected ICriteria<T> CreateTestCriteria<T>()
+ protected ICriteria<T> CreateTestQueryOver<T>()
{
return new CriteriaImpl<T>(new CriteriaImpl(typeof(T), null));
}
+ protected ICriteria<T> CreateTestQueryOver<T>(Expression<Func<object>> alias)
+ {
+ string aliasContainer = ExpressionProcessor.FindMemberExpression(alias.Body);
+ return new CriteriaImpl<T>(new CriteriaImpl(typeof(T), aliasContainer, null));
+ }
+
protected void AssertCriteriaAreEqual(ICriteria expected, ICriteria actual)
{
AssertObjectsAreEqual(expected, actual);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|