|
From: <aye...@us...> - 2009-05-22 18:29:02
|
Revision: 4358
http://nhibernate.svn.sourceforge.net/nhibernate/?rev=4358&view=rev
Author: ayenderahien
Date: 2009-05-22 18:28:52 +0000 (Fri, 22 May 2009)
Log Message:
-----------
NH-1791 - Allow more natural syntax for passing multiple projections on a criteria query
BREAKNING CHANGE - If you are inheriting from ICriteria, you would need to change the method signature. This is very rare, so I don't expect this to be a real problem
This change is source code compatible for users of ICriteria.SetProjection, however.
Modified Paths:
--------------
trunk/nhibernate/src/NHibernate/ICriteria.cs
trunk/nhibernate/src/NHibernate/Impl/CriteriaImpl.cs
Modified: trunk/nhibernate/src/NHibernate/ICriteria.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/ICriteria.cs 2009-05-22 16:29:11 UTC (rev 4357)
+++ trunk/nhibernate/src/NHibernate/ICriteria.cs 2009-05-22 18:28:52 UTC (rev 4358)
@@ -72,7 +72,7 @@
/// determines the overall "shape" of the query result.
/// </para>
/// </remarks>
- ICriteria SetProjection(IProjection projection);
+ ICriteria SetProjection(params IProjection[] projection);
/// <summary>
/// Add an Expression to constrain the results to be retrieved.
Modified: trunk/nhibernate/src/NHibernate/Impl/CriteriaImpl.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Impl/CriteriaImpl.cs 2009-05-22 16:29:11 UTC (rev 4357)
+++ trunk/nhibernate/src/NHibernate/Impl/CriteriaImpl.cs 2009-05-22 18:28:52 UTC (rev 4358)
@@ -439,9 +439,27 @@
return this;
}
- public ICriteria SetProjection(IProjection projection)
+ public ICriteria SetProjection(params IProjection[] projections)
{
- this.projection = projection;
+ if(projections==null)
+ throw new ArgumentNullException("projections");
+ if(projections.Length ==0)
+ throw new ArgumentException("projections must contain a least one projection");
+
+ if(projections.Length==1)
+ {
+ projection = projections[0];
+ }
+ else
+ {
+ var projectionList = new ProjectionList();
+ foreach (var childProjection in projections)
+ {
+ projectionList.Add(childProjection);
+ }
+ projection = projectionList;
+ }
+
projectionCriteria = this;
SetResultTransformer(CriteriaSpecification.Projection);
return this;
@@ -810,9 +828,9 @@
return this;
}
- public ICriteria SetProjection(IProjection projection)
+ public ICriteria SetProjection(params IProjection[] projections)
{
- root.SetProjection(projection);
+ root.SetProjection(projections);
return this;
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|