NHIBernate LINQ BIGINT casting

I'm trying to understand the NHibernate SQL output for this entity:

public class Person
{
    public virtual long Id { get; set; }
    public virtual long Number { get; set; }
}

      

When I write:

var maxNumber = s.Query<Person>().Max(p => p.Number);

      

The generated SQL looks like this:

select cast(max(person0_.Number) as BIGINT) as col_0_0_ from Person person0_

      

Why cast if column Number

bigint

?

I am using NHibernate 3.2, SQL Server 2008 R2, the mapping is defined like this:

<class name="NhMappingTest.Person, NhMappingTest">
      <id name="Id"><generator class="increment" /></id>
      <property name="Number" />
</class>

      

+3


source to share


1 answer


It is not necessary. This is an implementation detail:

protected HqlTreeNode VisitNhMax(NhMaxExpression expression)
{
    return _hqlTreeBuilder.Cast(
        _hqlTreeBuilder.Max(
            VisitExpression(expression.Expression).AsExpression()), 
            expression.Type);
}

      



So the code blinds the result.

+1


source







All Articles