开发者

nhibernate queryOver projection syntax

开发者 https://www.devze.com 2023-01-31 12:09 出处:网络
I am trying some code out from a 开发者_高级运维NH 3.0 Cookbook, and wondering why I can\'t get the code below to compile. I think the QueryProjectionBuilder that should make this work is in \"NHibern

I am trying some code out from a 开发者_高级运维NH 3.0 Cookbook, and wondering why I can't get the code below to compile. I think the QueryProjectionBuilder that should make this work is in "NHibernate.Criterion.Lambda" but the using directive for it doesn't help.

The problems are the SelectGroup and SelectAvg parts. Assuming the syntax from the book is correct, can anyone see a missing reference here?

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]
                        });

        }
    }
}


You have to use .SelectList instead of .Select

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号