var employeePayDetails = (from p in Catalog.Providers
where p.Key == providerKey
from a in p.Appointments
from e in a.Employee.Services
from l in a.Allocations
from ip in l.InvoicePayments
where (a.Employee != null && a.Created >= begin && a.Created <= end) where (e.Service.Id==l.Service.Id)
select new
{
ServiceName = l.Service,
CustomersServiced = l.Pet.Name + " " + a.Owner.LastName,
AppointmentDate = a.Created,
EmployeeName = a.Employee.Name,
PaymentOptionType = e.PaymentOption,
RateValue = e.Rate,
WorkedHours=l.End-l.Start,
PayAmount= ?
}).ToList();
在上面的Entity框架查询中,我需要根据下面提到的switch语句计算 PayAmount 。
switch (PaymentOption)
{
case 1:
PayAmount= WorkedHours * RateValue ;
break;
case 2:
PayAmount = RateValue ;
break;
case 3:
PayAmount = LatestTotal ;
break;
}
那么我怎样才能将实体框架查询的上述switch语句值作为 PayAmount ?
答案 0 :(得分:2)
标准if
应该有效:
PayAmount= (e.PaymentOption == 1 ? (l.End-l.Start) * e.Rate : (e.PaymentOption == 2 ? e.Rate : LatestTotal ))