none
Validation Errors while saving parent and child entities in Entity Framework 6 RRS feed

  • Question

  •  

    Unable to update parent elements in entity framework. For an attached entity when I am trying to set the ActiveInd state to 0 I am getting an unusual error as described below.

     public override void Delete(Architect item)
            {
                // Implement Delete logic based on the availability of 'ActiveInd', Update to 0
                // If not available then delete the record permanently
    
                try
                {
                     item.ActiveInd = false;
                    _entities.Entry(original).CurrentValues.SetValues(item);
                    _entities.SaveChanges();
    
                    // Set the object to be deleted
                    //_entities.Entry(item).State = EntityState.Deleted;
                    //_entities.SaveChanges();
                }
                catch (Exception ex)
                {
                    throw ex;
                }
    
            }
    Causes to throw Entity Validation Errors on Architect.Contact and Architect.Contact.Address entites

    Errors says that FirstName, LastName and PhoneNumber on Contact field is missing.


    Whereas all these members already have some data as shown below:


    Similar error for Archtiect.Contact.Address for 3 required properties.

    Any suggestion on this.

    Thanks in advance.


    • Edited by Gururaj S A Tuesday, February 26, 2019 12:27 PM Had to add some more details.
    • Moved by CoolDadTx Tuesday, February 26, 2019 7:02 PM EF related
    Tuesday, February 26, 2019 12:25 PM

All replies

  • Hi Gururaj S A,

    According to your description, error message, screenshot, I am not sure what cause the issue, could you please share a simple complete sample to reproduce the issue via OneDrive, it will be beneficial to resolve the issue.

    Best regards,

    Zhanglong


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Wednesday, February 27, 2019 7:55 AM
    Moderator