问题
I am using C# Dapper with MYSQL.
I have a list of classes that i want to insert into MySQL table.
I used to do it using TVP in MS SQL, how do we do it in MySQL.
回答1:
Disclaimer: I'm the owner of Dapper Plus
This project is not free but supports MySQL and offers all bulk operations:
- BulkInsert
- BulkUpdate
- BulkDelete
- BulkMerge
And some more options such as outputting identity values:
// CONFIGURE & MAP entity
DapperPlusManager.Entity<Order>()
.Table("Orders")
.Identity(x => x.ID);
// CHAIN & SAVE entity
connection.BulkInsert(orders)
.AlsoInsert(order => order.Items);
.Include(x => x.ThenMerge(order => order.Invoice)
.AlsoMerge(invoice => invoice.Items))
.AlsoMerge(x => x.ShippingAddress);
来源:https://stackoverflow.com/questions/55359772/how-to-bulk-insert-in-sql-using-dapper-in-c-sharp