Your best bet might be looking at support for these things in regular java Hibernate. Usually I look for documentation there first since its a little more mature and there are more examples.
Projections are exactly what you would think, a SQL select clause. You can use them with criteria queries to bring only a certain number of columns back instead of hydrating the entire entity. You can also do aggregations: Count, Sum, Min, Max and Grouping.
I do not know much about result transformers, this tip came from an email. Here is the sample code I was given.
Code:
[Test]
public void QueryTestWithStrongTypeReturnValue()
{
using (ISession session = OpenSession())
{
ICriteria c = session.CreateCriteria(typeof(ProjectionTestClass));
NHibernate.Transform.IResultTransformer trans = new NHibernate.Transform.AliasToBeanConstructorResultTransformer(
typeof(ProjectionReport).GetConstructors()[0]
);
c.SetProjection(Projections.ProjectionList()
.Add(Projections.Avg("Pay"))
.Add(Projections.Max("Pay"))
.Add(Projections.Min("Pay")));
c.SetResultTransformer(trans);
ProjectionReport report = c.UniqueResult<ProjectionReport>();
Assert.AreEqual(report.MinPay, 2.5);
Assert.AreEqual(report.MaxPay, 4);
Assert.AreEqual(report.AvgPay, 1);
}
}
The above code from
Ayende Rahien, his program, NHibernate Query Generator and Rhino-Commons are two that I actively use in my current projects.
When in doubt, look at the NHibernate source, its amazing what you may uncover.
Adam