如何在C#中使用Dapper批量插入SQL [英] How to bulk insert in SQL using Dapper in C#
本文介绍了如何在C#中使用Dapper批量插入SQL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在将C#Dapper与MYSQL一起使用。
I am using C# Dapper with MYSQL.
我有一个要插入MySQL表的类列表。
I have a list of classes that i want to insert into MySQL table.
我以前在MS SQL中使用TVP来做到这一点,在MySQL中如何做到这一点。
I used to do it using TVP in MS SQL, how do we do it in MySQL.
推荐答案
免责声明:我是 Dapper Plus
该项目不是免费的,但支持MySQL并提供所有批量操作:
This project is not free but supports MySQL and offers all bulk operations:
- BulkInsert
- BulkUpdate
- BulkDelete
- BulkMerge
- 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);
这篇关于如何在C#中使用Dapper批量插入SQL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文