Support Convert.ToXXX() and various Parse methods

Description

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.

Environment

None

Activity

Show:

Alex Zaytsev December 11, 2013 at 1:59 AM

Pull request has been commited ac871b36013b0920723fec21e879773ea5390d4d

Leonard Labat March 20, 2013 at 11:18 AM

Fixed

Details

Assignee

Reporter

Components

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
Who's Looking?