Base solution for your next web application
Open Closed

[RESOLVED] Entity update is blanking out related entity #2666


User avatar
0
exlnt created

I have an entity update method that is setting one of my key columns in one of my related tables for the entity with a NULL.

The issue happens from the Edit modal to the update company method in my app service. It updates the company entity table just fine. But then it seems to also NULL out the company Id column in my CompanyAddress table.

I have emailed you my solution for your review. Can you help to identify why this is happening? Thanks!


3 Answer(s)
  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    Sorry for the late reply, I have missed your email somehow. If you move this definition in EditCompanyDtoForUpdate

    public List<EditCompanyAddressDto> Addresses { get; set; }
    

    to EditCompanyDto, your problem will be solved.

    You don't send address data when updating company but you map your dto to company entity. In this way, entities Addresses list becomes empty and your filed updated as null.

  • User Avatar
    0
    exlnt created

    Thank you very much! That did the trick!

    I'm still struggling to come to grips with these DTO's. But I'm learning slowly! :D

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    I'm glad that it worked :).