7

我正在尝试从 NH 3.0 Cookbook 中提取一些代码,并想知道为什么我无法编译下面的代码。我认为应该使这项工作的 QueryProjectionBuilder 在“NHibernate.Criterion.Lambda”中,但它的 using 指令没有帮助。

问题是 SelectGroup 和 SelectAvg 部分。假设书中的语法是正确的,任何人都可以在这里看到缺少的参考吗?

namespace Queries.Implementations
{
using System;
using System.Collections.Generic;
using System.Linq;
using Eg.Core;
using NHibernate;
using NHibernate.Criterion;
using NHibernate.Criterion.Lambda;

    public class QueryOverQueries : CookbookQueriesBase
    {

        public override IEnumerable<NameAndPrice> GetAvgDirectorPrice(ISession session) {
            return _session.QueryOver<Movie>()
                .Select(list => list
                                    .SelectGroup(m => m.Director)
                                    .SelectAvg(m => m.UnitPrice)
                )
                .List<object[]>()
                .Select(props =>
                        new NameAndPrice
                        {
                            Name = (string) props[0],
                            Price = (decimal) props[1]
                        });

        }
    }
}
4

1 回答 1

10

你必须使用.SelectList而不是.Select

于 2010-12-19T11:32:44.363 回答