我的应用程序有一些有线问题。当我把一个调试并检查这些值正确更新。但如果它运行没有调试,值不能正确更新。如何摆脱此问题。扩展方法无法正常工作
这是我的静态扩展方法。
public static decimal CalculateTotal(this Invoice invoice)
{
var subTotal = invoice.SubTotal;
var total = subTotal;
if (invoice.Fees == null || !invoice.Fees.Any()) return Math.Round(total, 2);
foreach (var fee in invoice.Fees.Where(f => !f.IsCancelled).OrderBy(f => f.Precedence))
{
var value = 0m;
if (fee.Percentage.HasValue)
{
if (fee.Total != null) value += fee.Total.Value;
}
if (fee.Fixed.HasValue)
{
value += fee.Fixed.Value;
}
total += value;
}
return Math.Round(total, 2);
}
上面的方法调用如下。
public InvoiceDetail Booking(my parameters)
{
var bookingProcessModel = BookingProcessDetails(providerKey, ownerKey, serviceId, petKeys, selectedDates, selectedTimes, selectedExtraServices, selectedResourceId, userType, discount, specialPrices, isProviderPickUp);
bookingProcessModel.Invoice.CalculateTotal();//here I'm calling that method
Catalog.SaveChanges();//data base save
var invoiceDetailModel = GetInvoiceDetailModel(bookingProcessModel.AppointmentModel, bookingProcessModel.Invoice);
return invoiceDetailModel;
}
上述方法,数据的基础上节约值之后是wrong.But当我把一个调试上面的扩展方法,检查它的工作properly.What是问题?任何帮助?
在调试模式下 - Catalog.SaveChanges()更新值是否符合您的期望? – swapneel
@swapneel如果我对'bookingProcessModel.Invoice.CalculateTotal()'进行调试,那么它的工作正常。 :(否则不是。 – Sampath