OK, so I have a business object, say Order (which was already created and saved), which has a collection of Products. I bind the Products collection to a list box on an .aspx page. On the page users can edit (add and remove Products) the list (Order). Once they are done making changes they press the "Save" button and I (will) update the changes to the database.
My question is this: when they press "Save" I load the current Order from the database so I have a copy of what the Order IS and then the page has the data that the Order SHOULD BE. So, I copy the data (irrelevent for this question), then I need to synch the (Product) collections. In this example the data in each Product is irrelevent. I simply want to get the collection synched up. How are people doing this? I see 3 options:
1. Clear out the Order's Product collection and recreate each item that should be in the collection. Since there are not a lot of items in the collection this is feasible. However, this would generate extra DB operations and is kind of ugly, IMO.
2. Brute force check whether each Product in the Page's list is in the Order's list. If not add the Product. Then, check whether each Product in the Order's list is in the Page, if not, then remove it. This works, but seems pretty inefficient...
I'm leaning towards #2 and will probably implement it, but I just wondered how anyone else handled this situation. It would be easy with WinForms since the objects would all still be in memory and removing them from the Page's (Form) would also remove from the Collection (and vice-versa). With ASP.NET we have to do some trickery...
Smoke