WOW, there are some pretty major bugs in this part of the framework.
Here's my favorite so far:
The query parameters get way out of order when specifying a
combination of standard criteria and projection criteria. For example
take this query:
string formalname = s.CreateCriteria(typeof(Student))
.SetProjection(new SqlFunctionProjection("concat",
NHibernateUtil.String,
new ConstantProjection("Mr. "), Projections.Property("Name")))
.Add(Restrictions.Gt("id", 2L)).UniqueResult<string>();
Seems simple enough. We're adding 'Mr. ' to all names with an ID
greater than 2. Here's what the unmodified source returns.
NHibernate: INSERT INTO Student (Name, preferredCourseCode, studentId)
VALUES (@p0, @p1, @p2); @p0 = 'ayende', @p1 = '', @p2 = '27'
NHibernate: SELECT (@p0+this_.Name) as y0_ FROM Student this_ WHERE
this_.studentId > @p1; @p0 = '2', @p1 = 'Mr. '
Ouch. Looks like the parameter order is specified in
CriteriaQueryTranslator.GetQueryParameters() as standard criteria
first then projection criteria. I'm going to try and fix this along
with my group by stuff. Sure hope that it ends up getting used, I'd
hate to go to all this trouble just to have it dumped because it
doesn't match the Java version.... which this particular function
doesn't match already, I checked.
-Will