0
在linq查詢中選擇case語句。datediff with case statement in select query linq
這裏是SQL查詢:
select case when DATEDIFF(day,convert(varchar,Min([Order].CreatedOnUtc),101),convert(varchar,Max([Order].CreatedOnUtc),101)) = 0 then
Sum([Order].OrderSubtotal)
else
case when (DATEDIFF(day,convert(varchar,Min([Order].CreatedOnUtc),101),convert(varchar,Max([Order].CreatedOnUtc),101))/30) = 0 then Sum([Order].OrderSubtotal) else
Sum([Order].OrderSubtotal)/
(DATEDIFF(day,convert(varchar,Min([Order].CreatedOnUtc),101),convert(varchar,Max([Order].CreatedOnUtc),101))/30)
end
end as 'Account Value' from [order] where And Account.ID = @Act_ID
在這裏,我想代碼:
var query = _orderRepository.Table;
query = query.Where(o => o.AccountId == accountId);
在查詢我收到我的價值。
查詢語句後應該怎麼寫? 如何使用linq編寫case語句?
我希望下面的鏈接將有所幫助。 [linq-case-statement-stackoverflow](http://stackoverflow.com/questions/936028/linq-case-statement)[選擇案例在LINQ - Stackoverflow](http://stackoverflow.com/questions/ 4244023/select-case-in-linq) – Venu
我已經看到這個聲明在stackoverflow ..但在我的情況下DATEDIFF與兩個case語句..所以你可以指導我?? – Manoj
var query = _orderRepository.Table; query = query.Where(o => o.AccountId == accountId); var MinDate =(從查詢中選擇d.CreatedOnUtc).Min(); var MaxDate =(從查詢中的d選擇d.CreatedOnUtc).Max(); var rateSum =(query.Sum(d => d.OrderSubtotal)); 查詢= query.Where(C => (DbFunctions.DiffDays(爲MinDate,MAXDATE)== 0) 「rateSum」:???(DbFunctions.DiffDays(爲MinDate,MAXDATE)/ 30 == 0) 「rateSum」「 (rateSum /(DbFunctions.DiffDays(爲MinDate,MAXDATE)/ 30)「); – Manoj