【发布时间】:2016-10-07 01:28:59
【问题描述】:
我正在开始研究 NHibernate,但有一个我无法解决的问题,不知道是否有人可以帮助我。
映射“正常”工作,但是当我尝试进行分组和求和时,应用程序返回以下错误:
“无法解析属性:Course.Price of: Persistence.POCO.RequestDetail”
var criteria = session.CreateCriteria(typeof(RequestDetail))
.SetProjection(
Projections.ProjectionList()
.Add(Projections.RowCount(), "RowCount")
.Add(Projections.Sum("Course.Price"), "Price")
.Add(Projections.GroupProperty("Request"), "RequestId")
)
.AddOrder(Order.Asc("RequestId"))
.SetResultTransformer(Transformers.AliasToEntityMap)
.List();
注意 1:当我输入代码 .Add(Projections.Sum ("Course.Price"), "Price") 时,应用程序会正确返回结果。
注意 2:我唯一能做的就是运行下面的代码:
query.Length = 0;
query.AppendLine("select");
query.AppendLine(" s.Id,");
query.AppendLine(" s.Identification,");
query.AppendLine(" sum(c.Price) as Total");
query.AppendLine("from");
query.AppendLine(" Student s");
query.AppendLine("inner join");
query.AppendLine(" Request r on r.StudentId = s.Id");
query.AppendLine("inner join ");
query.AppendLine(" Requestdetail rq on rq.RequestId = r.Id");
query.AppendLine("inner join");
query.AppendLine(" Course c on c.Id = rq.CourseId");
query.AppendLine("Group by");
query.AppendLine(" s.Id, s.Identification");
query.AppendLine("Order by");
query.AppendLine("s.Identification");
IQuery criteria = session.CreateSQLQuery(query.ToString())
.SetResultTransformer(Transformers.AliasToBean<Teste>());
IList<Teste> teste = criteria.List<Teste>();
有人遇到过这个问题吗?
【问题讨论】:
标签: c# nhibernate group-by sum hql