nhibernate queryOver 投影语法
我正在尝试 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]
});
}
}
}
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]
});
}
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您必须使用
.SelectList
而不是.Select
You have to use
.SelectList
instead of.Select