0

I want to update a parent entity ONLY that contains a child entity also preventing child from inserting a new record is null for the child.

But I am receiving the error:

Validation failed for one or more entities. See 'EntityValidationErrors' property for more details.

or sometimes complaining that:

Child entity is null therefore cannot update

Suppose I have:

    public void updateParentModel(myModel model)
    {
        mycontext.Entry(model).State = System.Data.Entity.EntityState.Modified;
        mycontext.SaveChanges();
    }

I tried this below and it's also not working:

    //mycontext.Entry(model).Property(x => x.Serviced).IsModified = true;
RickL
  • 3,318
  • 10
  • 38
  • 39
MVC newbie
  • 579
  • 3
  • 9
  • 26
  • Child entity within the model is null, rebind it when updating the parent entity. – Sajal May 02 '17 at 09:57
  • What are the validation errors you are getting? Also, could you provide the code for parent and child entities? – Amanvir Mundra May 02 '17 at 12:43
  • See [here](http://stackoverflow.com/questions/25441027/how-do-i-stop-entity-framework-from-trying-to-save-insert-child-objects) – Steve Greene May 02 '17 at 13:24
  • @SteveGreene i've look into that before coming here.Dettach doesnt allow me to save my parent entity. @AmanvirSinghMundra no matter what validation errors. i just don want to validate child entity field by field and child by child. @sajal reason to rebind? when i retrive the parent eitity,the child is already `null` there is nothing for me to rebind or insert or update for the child. – MVC newbie May 03 '17 at 00:44

0 Answers0