换句话说,代码语言。并假设发票是从上下文中挑选的。
无阻无变
void updateInvoice(DataBaseEntities context, Invoice invoice, float amount, string currency)
{
invoice.amount = amount;
invoice.currency = currency;
context.SaveChanges();
}
防止无变化
void updateInvoice(DataBaseEntities context, Invoice invoice, float amount, string currency)
{
var needToUpdate = false;
if ( invoice.amount != amount )
{
invoice.amount = amount;
needToUpdate = true;
}
if (invoice.currency != currency)
{
invoice.currency = currency;
needToUpdate = true;
}
if (needToUpdate) context.SaveChanges();
}
现实更多的是复杂的数据库和几十万条记录。
我应该更喜欢什么来优化流程?