I have two classes
public class InvoiceRow
{
public int Id { get; set; }
public int InvoiceId { get; set; }
public int ProductId { get; set; }
public virtual Product Product { get; set; }
public int Amount { get; set; }
}
public class Invoice
{
public int Id { get; set; }
private ICollection<InvoiceRow> _rows;
public virtual ICollection<InvoiceRow> Rows => _rows ?? (_rows = new List<InvoiceRow>());
}
I use Update method in the repository class
public void Update(Invoice record)
{
dB.Invoices.Update(record);
dB.SaveChanges();
}
It works for updating values in the collection of rows and adding new rows as well, however it doesn't remove items, if I pass object with less rows than it has in the database. What is the best approach to do it?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…