10

can anyone help me figure out what I'm doing wrong. I'm new to nhibernate and I'm finding it quite hard to really get comfortable with it. I have this query:

        var results2 = (from purchase in _session.Query<Purchase>()
                        group purchase by new { purchase.symbol } into purchases
                        select new Quote()
                        {
                            shares= purchases.Sum(p => p.shares)
                        }).ToList();

but I get notsupportedexception and the error message is just newexpression.

NOtherDev
  • 9,542
  • 2
  • 36
  • 47
Leon
  • 141
  • 3
  • 2
    Group by has limited support currently in Linq2NH. I know for a fact it currently doesn't support multiple column group by clauses. I can't remember how it supports single column group by clauses – cdmdotnet Jan 11 '11 at 10:28

1 Answers1

1

Looking at the question's date, I guess that question was about NHibernate pre-3.2.

Assuming that your Quote is a simple POCO class and you use NHibernate 3.2 or later, this query works fine - see my blog post for some details about GroupBy capabilities in NHibernate.

So the solution simply is to upgrade.

NOtherDev
  • 9,542
  • 2
  • 36
  • 47