|
From: <Ric...@us...> - 2009-06-24 20:48:45
|
Revision: 4527
http://nhibernate.svn.sourceforge.net/nhibernate/?rev=4527&view=rev
Author: RicBrown
Date: 2009-06-24 20:48:32 +0000 (Wed, 24 Jun 2009)
Log Message:
-----------
Added ICriteria<T>.Where() to allow more natural queries.
Modified Paths:
--------------
trunk/nhibernate/src/NHibernate/ICriteriaOfT.cs
trunk/nhibernate/src/NHibernate/Impl/CriteriaOfTImpl.cs
trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/IntegrationFixture.cs
trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/Mappings.hbm.xml
trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/Model.cs
Modified: trunk/nhibernate/src/NHibernate/ICriteriaOfT.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/ICriteriaOfT.cs 2009-06-24 19:58:07 UTC (rev 4526)
+++ trunk/nhibernate/src/NHibernate/ICriteriaOfT.cs 2009-06-24 20:48:32 UTC (rev 4527)
@@ -29,6 +29,13 @@
ICriteria<T> And(Expression<Func<T, bool>> expression);
/// <summary>
+ /// Identical semantics to Add() to allow more readable queries
+ /// </summary>
+ /// <param name="expression">Lambda expression</param>
+ /// <returns>criteria instance</returns>
+ ICriteria<T> Where(Expression<Func<T, 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-24 19:58:07 UTC (rev 4526)
+++ trunk/nhibernate/src/NHibernate/Impl/CriteriaOfTImpl.cs 2009-06-24 20:48:32 UTC (rev 4527)
@@ -31,6 +31,12 @@
return this;
}
+ ICriteria<T> ICriteria<T>.Where(Expression<Func<T, bool>> expression)
+ {
+ _criteria.Add(expression);
+ return this;
+ }
+
IList<T> ICriteria<T>.List()
{
return _criteria.List<T>();
Modified: trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/IntegrationFixture.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/IntegrationFixture.cs 2009-06-24 19:58:07 UTC (rev 4526)
+++ trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/IntegrationFixture.cs 2009-06-24 20:48:32 UTC (rev 4527)
@@ -72,9 +72,9 @@
using (ISession s = OpenSession())
using (ITransaction t = s.BeginTransaction())
{
- s.Save(new Person() { Name = "test person 1" });
- s.Save(new Person() { Name = "test person 2" });
- s.Save(new Person() { Name = "test person 3" });
+ s.Save(new Person() { Name = "test person 1", Age = 20 });
+ s.Save(new Person() { Name = "test person 2", Age = 30 });
+ s.Save(new Person() { Name = "test person 3", Age = 40 });
t.Commit();
}
@@ -83,7 +83,8 @@
{
IList<Person> actual =
s.QueryOver<Person>()
- .And(p => p.Name == "test person 2")
+ .Where(p => p.Name == "test person 2")
+ .And(p => p.Age == 30)
.List();
Assert.That(actual.Count, Is.EqualTo(1));
Modified: trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/Mappings.hbm.xml
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/Mappings.hbm.xml 2009-06-24 19:58:07 UTC (rev 4526)
+++ trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/Mappings.hbm.xml 2009-06-24 20:48:32 UTC (rev 4527)
@@ -8,6 +8,7 @@
<generator class="native"/>
</id>
<property name="Name" />
+ <property name="Age" />
</class>
<class name="Child">
Modified: trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/Model.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/Model.cs 2009-06-24 19:58:07 UTC (rev 4526)
+++ trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/Model.cs 2009-06-24 20:48:32 UTC (rev 4527)
@@ -9,6 +9,7 @@
{
public virtual int Id { get; set; }
public virtual string Name { get; set; }
+ public virtual int Age { get; set; }
}
public class Child
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|