How to find out when to insert, delete or update based on a C # list?

Let's say that I have three tables "Person", "Area" and "Person_Area". Each person can work in many areas, and in each area there can be many people. "person_Area" is a bridge table that contains person_id and area_id

In my code, I have two lists of a list of lists arranged in human form. The list field contains all available areas, and in the list field two can be filled with areas from the list one at a time based on the user's choice. The areas that fall into the list box two are the areas in which the person is located.

All this is beautiful and easy, but when I decide to save to my database, I’m not sure how to insert, update, delete the table "person_Area". I don’t want to reinsert the area for the person if it is already in the table and if the user removes the area from the list 2 window, how does the code know to delete it when I send it back to the server?

Would it be wise to simply delete all the entries in the "Person_Area" table for a specific person, and then re-add all the current user settings? or is there a better option? I'm at a dead end.

+3
source share
2 answers

. , , - .

, :

  • "" ( ​​, ), ( , ) . ( , - , , SAVE, . , INSERT, DELETE)

  • person_area ( , ). . , , DELETE. , , INSERT.

, , , , .

+2

MERGE, . MERGE INSERT, UPDATE DELETE .

0

Source: https://habr.com/ru/post/1762743/


All Articles