1

I have below classes

public class Parent 
{
   public int ID {get;set;}
   public string Name {get;set;}
   public List<Child> Children {get;set;}      
}

public class Child
{
  public int ID {get;set;}
  public string AnotherProp {get;set;}
  public int ParentId {get;set;}
}

Now my Parent entity has one row and it has 2 child rows.

From api, I got an update for that particular parent row as well as insert new child row (note: after inserting new one there will be 3 children). I am doing below to add new child to the parent.

 existingParent.Children.Add(newChild);
 context.Parents.SaveChangesAsync();

But I am getting the exception : Exception: DbUpdateConcurrencyException, ExceptionMessage: Database operation expected to affect 1 row(s) but actually affected 0 row(s). Data may have been modified or deleted since entities were loaded. Please advice.

0 Answers0