2011-02-18 76 views
0
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) 
} 

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

回答

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 }; 

希望这将有助于