Fixed
Details
Details
Assignee
Alex Zaytsev
Alex ZaytsevReporter
Oskar Berggren
Oskar BerggrenComponents
Fix versions
Affects versions
Priority
Who's Looking?
Open Who's Looking?
Created January 15, 2013 at 9:17 AM
Updated September 21, 2014 at 12:55 PM
Resolved December 11, 2013 at 2:05 AM
With QuantityPerUnit as string, queries such as
var maxInDb = db.Products.Max(p => Convert.ToInt32(p.QuantityPerUnit));
var maxInDb = db.Products.Max(p => int.Parse(p.QuantityPerUnit));
fail with "System.NotSupportedException : Expression type 'NhMaxExpression' is not supported by this SelectClauseVisitor." because NHibernate doesn't recognize the convert/parse methods. NHibernate should be fixed to support this family of methods.
This similar query
var maxInDb = db.Products.Max(p => (int)(object)p.QuantityPerUnit);
successfully runs with the following SQL
select
cast(max(product0_.QuantityPerUnit) as INT) as col_0_0_
from
Products product0_
which gives wrong results, since the SQL cast is happening outside the aggregate (so "99" is bigger than "100"). Such casts in C# isn't really valid, but in Linq2NH it should either give the correct result, or fail with an exception.