I have a question about Saving a list of object in ASP.NET MVC. First I'm not using EntityFramework or Nh like ORM tool, just use Ado.net
suppose I have an object Product, and I want to collect all the products data via javascript and batch update the product list in one call.
my question is when should I differentiate which item is inserted, updated, or deleted?
one strategy is that I have a enum property on the DTO object and also on the javascript ViewModel, and when I add an item into the viewModel, I marked this object to add, and if I changed one Item, I marked it to updated. so when this request come to the action, I can know which items to be insert or update.
- pros: it's easy on server side, don't need to differentiate the object status from server side.
- cons: if I want to publish this action to webapi that will be called by third party, that may need third party user to differentiate the state of the object.
differentiate the data from server side, just give me a list of object, on the server side, first retrive the current data from database, compare the data, then check which record to be inserted or updated.
- pros: all the compare are done from server side.
- cons: proformance issue
what ever the data passed from client, just remove the current data and insert the new data
I hope someone could give me an advice, what's the best practice to handle this situation, I think it's quite common but I can't find a best solution.