這是我的Service表的列:
id
serverPlace
count
這是我需要將其轉換為 Linq 的 SQL 查詢:
SELECT Service.id,
Service.serverPlace,
sum(Service.count * 12 MONTH(getdate())) AS sum
FROM Service
GROUP BY Service.id, Service.serverPlace;
我不知道如何sum使用 Linq轉換和實作部分。
uj5u.com熱心網友回復:
它應該是這樣的:
var month = DateTime.Now.Month;
var result = await dbContext.Services.GroupBy(r=> new { r.Id, r.ServerPlace })
.Select(r=> new {
r.Key.Id,
r.Key.ServerPlace,
Sum = r.Sum(q=> q.Count*12 month)
}).ToArrayAsync();
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/371739.html
