2
我有一個LINQ查詢是這樣的:使用case語句
var trfplanList = (from at in entities.tdp_ProviderAccomodationType
join ap in entities.tdp_ProviderAccomodationTariffPlan on at.PATID equals ap.FK_PATID
join ac in entities.tdp_ProviderAccomodationCategory on ap.FK_PACID equals ac.PACID
where at.FK_ProviderID == CityID && at.IsApproved == 0 && ap.IsApproved == 0 && ac.AccomodationCategory == "Double Occupy"
orderby at.AccomodationType,ap.FromDate,ap.SType
select new AccomodationTariff
{
AccomodationType = at.AccomodationType,
SType = ap.SType,
FromDate = Convert.ToDateTime(ap.FromDate),
ToDate = Convert.ToDateTime(ap.ToDate),
RoomTariff = Convert.ToDecimal(ap.Rate),
ExPAXRate = Convert.ToDecimal(at.PerPaxRate)
}).ToList();
我有兩個問題:
我不能轉換值,而在選擇新的分配{}塊?它在項目中給我一個錯誤。
我希望在從數據庫例如SQL選擇
ExPAXRate
使用 '案例' 我以前寫:CASE ap.SType如果 '淡季',那麼at.PerPaxRateOS ELSE at.PerPaxRate END AS ExPAXRate
我可以在linq查詢中使用這樣的東西嗎?
ExPAXRate = at.OffSeason? at.PerPaxRateOS:at.PerPaxRate,這裏我想檢查一下這樣的ExPAXRate = ap.SType ==「Off Season」? at.PerPaxRateOS:at.PerPaxRate,但它給了我一個錯誤 – DharaPPatel 2013-04-25 04:30:01
okey我得到的解決方案,我應該寫:ExPAXRate =(ap.SType ==「Off Season」)? at.PerPaxRateOS:at.PerPaxRate – DharaPPatel 2013-04-25 05:53:14