I got an n:m relationship between these three tables: Products, Keywords and ProductKeywords
Now everytime I update a Product, I provide a List<Keyword> with the new chosen keywords. This collection can contain Keywords that are already chosen as the product keywords, as well as new or removed ones. Now I want to update this in my database.
For now I'm clearing the entire ProductKeywords table where ProductKeywords.ProductId equals Product.Id. Of course this produces very much overhead as it clears out any keywords for a specific product.
Is there an easy way to update this n:m relationship without clearing the entirety of the products keywords before? So it should remove ProductKeywords that are not present in the new List<Keyword> collection anymore but still in the table, as well as add new ProductKeywords that are not present in the table yet, but in the List<Keyword>. All others (present in table and present in List<Keyword>) should remain untouched to lessen the overhead.