我从数据库中抽出一堆时间表条目并使用它们来创建发票。一旦我保存了发票并有一个ID,我想用发票ID更新时间表条目。有没有办法批量更新实体而不一次加载一个实体?实体框架核心中的批量更新
void SaveInvoice(Invoice invoice, int[] timeEntryIds) {
context.Invoices.Add(invoice);
context.SaveChanges();
// Is there anything like?
context.TimeEntries
.Where(te => timeEntryIds.Contains(te.Id))
.Update(te => te.InvoiceId = invoice.Id);
}
而不是这样做,我添加了TimeEntries我保存之前的发票。 invoice.TimeEntries = context.TimeEntries.Where(te => timeEntryIds.Contains(te.Id))。ToArray() –