I am looking at Dapper as ORM for our next project, but something is not clear to me.
In this question there are answers on how to do inserts
, updates
and deletes
.
Since this question is already a bit older, maybe there are better ways now a days..
But my biggest concern is how to do an ApplyUpdates
on a list.
Suppose you have a List<Customer>
that is build like shown here
And suppose you show this list in a DataGridView.
Now, the user will
- alter the data of a few rows,
- insert a few new rows,
- delete a few rows
And when he clicks on the save button, at that time you want to save all these changes in this List<Customer>
to your database, using Dapper.
How can I go about that ?
If I have to loop through the list and for each row call an insert, update or delete
statement, then how can I determine what operation to use ? The deleted
rows will be gone from the list.
I also want to make sure that if one statement fails, all will be rollbacked.
And I need the primary key for all new rows returned and filled in the DataGridView.
In other words, all that ADO DataAdapter/DataTable does for you.
What is the best way to do this using Dapper
?
EDIT
The best way I can think of now is to keep 3 list in memory and when the user alters some data, add a row in the update list
, same for insert list
and deleted list
so I can run through these 3 list on the button click.
But I am hoping there is a better alternative build in Dapper
for this kind of situation.