0

I'm trying to implement the following SQL query with QueryOver:

SELECT [Time]/1000
FROM TableName
GROUP BY [Time]/1000

Here's my current attempt:

var result = session
    .QueryOver<TableName>
    .Select(Projections.GroupProperty(
        Projections.SqlFunction(
            new VarArgsSQLFunction("(", "/", ")"),
            NHibernateUtil.Int64,
            Projections.Property("Time")
            Projections.Constant(1000))
    ))
    .List<object>();

Unfortunately I get the following exception (GenericADOException):

could execute query
[ SELECT (this_.Time/@p0) as y0_ FROM [TableName] this_ GROUP BY (this_.Time/?) ]

And the inner exception:

Incorrect syntax near ?.

I can replace the "GroupProperty" with a "Sum" and it works. Any idea what's missing?


Update: Apparently it's a bug in NHibernate. See also this question.

Community
  • 1
  • 1
kshahar
  • 10,423
  • 9
  • 49
  • 73

1 Answers1

1

Why don't you just use Projections.SqlGroupProjection:

var result = session
    .QueryOver<TableName>
    .Select(Projections.SqlGroupProjection(
                        Time/1000 AS TimeValue", 
                        "Time/1000", 
                        new[]{"TimeValue"}, 
                        new[]{NHibernateUtil.Int32}))
    .List<object>();
Martin Ernst
  • 5,629
  • 2
  • 17
  • 14