To bulk insert data using Dapper in C#, you can use SqlBulkCopy class which is a part of ADO.NET. Here is an example code snippet on how to do a bulk insert using Dapper:
main.cs1238 chars49 lines
In the above code snippet, we first open a SqlConnection and begin a new transaction. We then create a new instance of SqlBulkCopy class and set the DestinationTableName and ColumnMappings properties. Finally, we call the WriteToServer method passing in the list of data to be inserted. Lastly, we commit the transaction and close the connection. In case of any exceptions, we catch and rollback the transaction.
gistlibby LogSnag