my application has 2 classes: PaymentMethod
& Currency
(Currency
is property of PaymentMethod
). When my app does upda
DbSet.Attach
is not recursive. You need to attach all the entities involed:
public override void Edit(MwbePaymentMethod entityToUpdate)
{
DbSet.Attach(entityToUpdate);
Context.Entry(entityToUpdate).State = EntityState.Modified;
if(entityToUpdate.BillingAddress != null)
{
DbSet.Attach(entityToUpdate.BillingAddress);
Context.Entry(entityToUpdate.BillingAddress).State = EntityState.Modified;
}
if(entityToUpdate.Currency != null)
{
DbSet.Attach(entityToUpdate.Currency);
Context.Entry(entityToUpdate.Currency).State = EntityState.Modified;
}
//manual update of properties
//Context.Entry(entityToUpdate.BillingAddress).State = EntityState.Modified;
//Context.Entry(entityToUpdate.Currency).State = EntityState.Unchanged;
}