Wednesday, November 21, 2018

EF Core Parent Child Updates

So I'm looking for an elegant solution to replace what I currently have which is an awful, upsetting attempt at coding.

I have a controller endpoint that receives a populated view model. When this is posted it has all the children, grandchildren, greatgrandchildren that should exist after the save.

ViewModel {

Guid Id;

List<Children> Children

}

Children {
Guid Id;

List<Grandchildren> Grandchildren

}

GrandChildren {
Guid Id;

List<GreatGrandChildren> GreatGrandchildren

}

GreatGrandchildren {

Guid Id;

}

Our current attempt at updating these entites is to get the ViewModel object from the database, set it's values..... Then search for any children that need to be updated and how they should be updated (by looping and looping and looping).

I feel like there must be an easier/more elegant way of updating these values but haven't been able to find anything when searching.

Has anyone got any tips or pointers?

EF Core Parent Child Updates Click here
  • Blogger Comment
  • Facebook Comment

0 comments:

Post a Comment

The webdev Team