首页新闻招聘找找看知识库
  • 错误信息:NHibernate.HibernateException: Query Source could not be identified: ItemName = g, ItemType = System.Linq.IGrouping`2[System.Int32,SW.Framework.Data.Entitys.ProductTest.ProductCombination], Expression = from IGrouping`2 g in {value(NHibernate.Linq.NhQueryable`1[SW.Framework.Data.Entitys.ProductTest.ProductCombination]) => GroupBy([c].ProductId, [c])}

    代码:

    var query = this.work.ProductCombinationRep.Query().GroupBy(c => c.ProductId)                                                     .Select(g => new                                                     {                                                         ProductId = g.Key,                                                         MaxPrice = g.Max(d => d.Price)                                                     })                                                     .Join(this.work.ProductRep.Query(), i => i.ProductId, j => j.Id, (i, j) => new                                                     {                                                         ProductId = i.ProductId,                                                         MaxPrice = i.MaxPrice,                                                         Name = j.Name                                                     }).ToList();

    PS: Product 是主表 ProductCombination是子表

    对ProductCombination进行分组,取出ProductId和MaxPrice, 最后将分组结果与主表Product做关联,最后将主表的Name信息及分组结果,全部查询出来,

    这种写法 Linq to sql,不会报错,在NH下会报这个错误,麻烦大家指点下!谢谢。

    NH 3.3版本.

登录后才能评论,请先登录注册