【问题标题】:nhibernate queryOver projection syntaxnhibernate queryOver 投影语法
【发布时间】:2010-12-19 06:35:51
【问题描述】:

我正在尝试从 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]
                        });

        }
    }
}

【问题讨论】:

    标签: c# nhibernate projection queryover


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 2015-01-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-10-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多