访问未包含在分组元素中的任何数据

时间:2011-02-18 09:46:40

标签: linq join linq-group

from teamBudget in TeamBudgets
where teamBudget.TeamID == 71002
join teamBroker in TeamBrokers on 71002 equals teamBroker.TeamID
join goal in Goals on teamBroker.GlobalBrokerID equals goal.GlobalBrokerID
group goal by goal.GlobalBrokerID into g

select new 
{
    // TeamID=teamBroker.TeamID,
    // MTDGoal=teamBudget.Sum(t => t.Budget),
    RevenueMTDCurrent = g.Sum(x => x.RevenueMTDCurrent)
}

评论部分是个问题。如何访问未包含在分组元素中的任何数据?

1 个答案:

答案 0 :(得分:2)

您需要对多个字段进行分组,然后才能访问该数据。

喜欢

var result = from i in
                     (from uh in db.UserHistories
                      where uh.User.UserID == UserID && uh.CRMEntityID == (int)entity
                      select new { uh.ActionID, uh.ActionType, uh.ObjectID })
                 group i by new { i.ActionID, i.ActionType, i.ObjectID } into g
                 select new { g.ActionID, g.ActionType, g.ObjectID };

希望这会有所帮助