1
  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();

在上面的实体框架查询中,我需要根据下面提到的 switch 语句计算PayAmount 。

switch (PaymentOption)
        {
           case 1:
                PayAmount= WorkedHours * RateValue  ;
                break;
            case 2:
                PayAmount = RateValue  ;
                break;
            case 3:
               PayAmount = LatestTotal  ;
                break;
        }

那么如何将实体框架查询的 switch 语句值作为PayAmount呢?

4

1 回答 1

2

标准if应该起作用:

PayAmount= (e.PaymentOption == 1 ? (l.End-l.Start) * e.Rate : (e.PaymentOption == 2 ? e.Rate : LatestTotal ))
于 2013-03-19T11:16:08.100 回答