I want to allow the user to delete or confirm multiple records by selecting them in a list and pressing delete/confirm button.
I’ve searched and it seems that EF doesn’t support batch update/delete, so what are the differences between the following approaches – and are there any negative implications from directly maniuplating the database.
1- use ExecuteSqlCommand method to run a query against database directly.
2- or create entities using selected Ids, set their state to modified/deleted and then call context.SaveChanges().
I would go for the second option – you have one transaction that covers all of the updates which is probably a good thing. (there are some cases where it is not)
This is also the easiest/quickest way to do this.
If you are going to have performance issues then go ahead and optimize this – change to SQL or change ORM to NHibernate or do whatever you wish.
Besides – there’s a rule that says write first, then optimize. Not the other way round.