我有一个连接几个表的查询。然后我需要按前两列进行分组,然后选择其余的值。现在它对前4列工作正常,但随后该组停止为所有列工作。我之前使用过类似的查询,它运行良好,所以如果有人有任何见解,我将非常感激。
var query = (from p in context.Process
join pf in context.table on p.ProcessID equals pf.ProcessID
join f in context.Flows on pf.FlowID equals f.FlowID
join d in context.Directions on pf.DirectionID equals d.DirectionID
join ft in context.FlowTypes on f.FlowTypeID equals ft.FlowTypeID
join fp in context.FlowProperties on f.FlowPropertyID equals fp.FlowPropertyID
join ug in context.UnitGroups on fp.UnitGroupID equals ug.UnitGroupID
group new { p, pf, f, d, ft, fp, ug} by new
{
FlowPropertyName = fp.Name,
ug.ReferenceUnit,
FlowDirection = d.FlowDirection,
FlowType = ft.Type,
//Won't group on these 3 column
//ProcessFlowResult =pf.Result,
//FlowName = f.Name,
//ProcessFlowID = pf.ProcessFlowID,
} into g
select new Model
{
FlowPropertyName = g.Key.FlowPropertyName,
ReferenceUnit = g.Key.ReferenceUnit,
FlowDirection = g.Key.FlowDirection,
FlowType = g.Key.FlowType,
//ProcessFlowResult = g.Key.ProcessFlowResult,
//FlowName = g.Key.FlowName,
//ProcessFlowID = g.Key.ProcessFlowID
}).AsQueryable();
return query;
答案 0 :(得分:0)
我明白了。
这是解决方案的缩小lambda版本,使用导航属性;-),以防万一其他人正在寻找类似的东西。
var query = context.ProcessFlows
.GroupBy(p => new
{
FlowPropertyName = p.Flow.FlowProperty.Name
})
.SelectMany(pf => pf.Select(p => new IntermediateFlow
{
FlowPropertyName = p.Flow.FlowProperty.Name,
ReferenceUnit = p.Flow.FlowProperty.UnitGroup.Name
})).AsQueryable();
return query.OrderBy(pFlow => new { pFlow.FlowPropertyName, pFlow.ReferenceUnit });