Uploaded image for project: 'NHibernate [Moved to GitHub]'
  1. NH-2347

Casts inside aggregate functions are incorrectly applied outside of them

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects versions: 3.0.0.Alpha2
    • Fix versions: 3.3.0.CR1
    • Components: Linq Provider
    • Labels:
      None
    • Sprint:

      Description

      Given a simple domain like:

      class Foo

      { int Bar }

      The following query:

      session.Query<Foo>().Sum(f => (long)f.Bar);

      Generates (unimportant stuff removed):

      select cast(sum(Bar) as bigint) from Foo

      This will fail (at least in SQL Server) if the SUM of that column overflows an int
      In contrast, for the exact same query Entity Framework correctly generates:

      select sum(cast(Bar as bigint)) from Foo

      (note the cast is inside the sum)

      Sorry for not attaching a proper test case. It shouldn't be hard to create, though (just map any entity and insert, for example, two records with int.MaxValue)

        Attachments

          Issue links

            Activity

              People

              • Assignee:
                Unassigned
                Reporter:
                diegose Diego Mijelshon
              • Votes:
                0 Vote for this issue
                Watchers:
                2 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:

                  Who's Looking?