NHibernate SelectMany在GroupBy引发“无法识别查询源”之后

时间:2019-05-29 07:42:06

标签: linq nhibernate linq-to-nhibernate

我正在尝试将SQL脚本转换为NHibernate Linq语句。但是我并没有走得很远:

var subQuery = selected.SelectMany(s => s.Attributes)
    .GroupBy(a => a.AttributeDefinition.Id)
    .SelectMany(g => g)
    .ToList();

此代码引发异常:

  

无法识别查询源:ItemName = g,ItemType = System.Linq.IGrouping'2 [System.Int32,DomainLayer.ProductManagement.SetPoints.SetPointAttribute],表达式=来自IGrouping'2 g in {来自SetPoint x in值(NHibernate.Linq.NhQueryable'1 [DomainLayer.ProductManagement.SetPoints.SetPoint])其中([x] .Product.Id == 3)其中([x] .Session.Id == 1)来自[ x]。属性选择[a] => GroupBy([a] .AttributeDefinition.Id,[a])}

不支持GroupBy上的SelectMany吗?还是我应该怎么写这个LINQ语句?

这是我要转换的SQL代码:

select s.*
  from (
    select max(a2.setpoint_id) as setpoint_id
    from
    SetPoints s2, 
    Attributes a2
    where
    a2.setpoint_id = s2.setpoint_id
    group by a2.attributedefinition_id
  ) as x
  inner join SetPoints s on x.setpoint_id = s.setpoint_id;

感谢您的帮助!

0 个答案:

没有答案