In the Oracle dialects we have:
RegisterFunction("atan2", new StandardSQLFunction("atan2",
NHibernateUtil.Single));
RegisterFunction("power", new StandardSQLFunction("power",
NHibernateUtil.Single));
Looking at atan2. this is the only trigonometric function that is
registered as Single - the others are all Double (even atan2 is double
in all other dialects). Consider the following LINQ expression:
....Select(o => Math.Round(Math.Atan2((double)o.Discount, 0.5d),
5)).ToList();
Because of the above function registration, it will fail with an
exception in HQLQueryPlan.PerformList() at line 138:
ArrayHelper.AddAll(combinedResults, tmp);
because the target list is List<double> (since this is the type of the
Linq expression), while the source list will be List<object>, with the
objects being of type single.
It smells a bit like two or three problems:
1) Is the function registration wrong? According to Oracle docs these
return NUMBER.
2) What if there is a situation where the SQL function really does
return a type different from the "matching" .Net method? Are we just
lucky that this happens so rarely that we haven't need to bother yet?
3) Come to think of it, if some function returns different types in
different dialects, this could be a problem even for HQL, if one tries
to be dialect agnostic in ones code?
/Oskar