2011-02-18 45 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 }; 

希望這將有助於