How to bulk insert in SQL using Dapper in C# [duplicate]

允我心安 提交于 2019-12-13 11:02:59

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!