NHibernate的queryOver投影语法 [英] nhibernate queryOver projection syntax

查看:242
本文介绍了NHibernate的queryOver投影语法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我出从NH 3.0食谱尝试一些代码,不知道为什么我不能让下面的代码进行编译。我的认为的,应该使这项工作QueryProjectionBuilder处于NHibernate.Criterion.Lambda,但用指令为它并不能帮助。



存在的问题是SelectGroup和SelectAvg份。假设从书的语法是正确的,任何人都可以在这里看到失踪的参考?



 命名空间Queries.Implementations 
{
使用系统;
使用System.Collections.Generic;
使用System.Linq的;
使用Eg.Core;
使用NHibernate;
使用NHibernate.Criterion;
使用NHibernate.Criterion.Lambda;

公共类QueryOverQueries:CookbookQueriesBase
{

公共覆盖的IEnumerable< NameAndPrice> GetAvgDirectorPrice(ISession的会话){
返回_session.QueryOver<电影>()
。选择(名单=>清单
.SelectGroup(M => m.Director)
.SelectAvg(M => m.UnitPrice)

的.List<对象[]>()
。选择(道具=>
新NameAndPrice
{
名称=(字符串)道具[0],
价格=(十进制)的道具[1]
});

}
}
}


解决方案

您必须使用 .SelectList 而不是。选择

$ b的$ b

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

这篇关于NHibernate的queryOver投影语法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆