【发布时间】:2014-04-22 17:49:39
【问题描述】:
我的应用有一些有线问题。当我进行调试并检查这些值是否正确更新时。但如果它在没有调试的情况下运行,则值不会正确更新。如何解决这个问题。
这是我的静态扩展方法。
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;
}
上述方法后,数据库保存值错误。但是当我对上述扩展方法进行调试并检查它是否正常工作时,问题是什么?有什么帮助吗?
【问题讨论】:
-
在调试模式下 - Catalog.SaveChanges() 是否按照您的预期更新值?
-
@swapneel 如果我对 'bookingProcessModel.Invoice.CalculateTotal()' 进行调试,那么它工作正常。 :( 否则不会。
标签: asp.net-mvc c#-4.0 entity-framework-4