我有一个这样的 linq 查询:
 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();
我有两个问题:
在 select new {} 块中分配时不能转换值吗?它给了我一个项目错误。
我想在从数据库中选择时使用“案例”
ExPAXRate,例如在我以前编写的 SQL 中:CASE ap.SType WHEN 'Off Season' THEN at.PerPaxRateOS ELSE at.PerPaxRate END AS ExPAXRate
我可以在 linq 查询中使用类似的东西吗?