Quantcast
Channel: ASP.NET Core
Viewing all articles
Browse latest Browse all 9386

Updating dependent Collection in EF 7/EF Core

$
0
0

Just wondering if you could advise on the best way to update a list of dependent objects in the database in EF7.

Using an Order –> Products example:
Lets say there are 5 products to choose from.
A new order comes in with products #1, #2, #3 selected (and saved to the DB).
However they can edit the order if they want - so later change it to products #1, #2 & #4.

Just doing a simple update doesn't get rid of the #3 product (just adds #4).
The simplest way I know is to literally delete all the order-products and then add the new list. But this seems like overkill as the #1 & #2 products don't need to be deleted.

Is this full-delete/add technique the best way or is there a simpler/better way in EF7!?


Viewing all articles
Browse latest Browse all 9386

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>