我有一個簡單的查詢在SQL:轉換SQL查詢LINQ
SELECT
l.State,
AVG(ls.Amount) As StateAvg
FROM
LeadSales ls
JOIN LEADS l on ls.LeadID = l.LeadID
GROUP BY
l.State
這工作:
有一個小麻煩,把它改爲LINQ(其中query
是LeadSales
表)的一個IQueryable ...
var StateList = from q in query
group q by new
{
q.Lead.State,
q.Amount // <--- it this corrcect?
} into g
select new AverageLeadSalesPriceItem
{
StateCode = g.Key.State,
StateAverage = ????
};
附:
public class AverageLeadSalesPriceItem
{
public string StateCode { get; set; }
public decimal? StateAverage { get; set; }
}
可能重複的[獲得平均使用LINQ](http://stackoverflow.com/questions/4590704/get-average-using-linq) – Pikoh
/\ @皮考我看了看那一個,但無法做出答案工作。 –
如何在C#中定義查詢? – jdweng