推荐一个Dapper的扩展库,提供高效的批量操作扩展方法(如批量插入、更新、删除和合并)。
01
项目简介
Dapper-Plus 是一个基于 Dapper 的扩展库,专注于提供高性能的批量操作功能。它不仅可以与 Dapper 一起使用,还兼容其他所有 Dapper 包。通过简单的配置和映射,开发者可以轻松实现高效的数据库批量操作。
02
核心功能
03
使用方法
1、安装依赖库
Install-Package Dapper.Plus
2、映射器
可以将实体与存储模型(数据库)进行映射,并配置执行批量操作的选项。
DapperPlusManager.Entity<Order>().Table("Orders")
.Identity(x => x.ID)
.BatchSize(200);
3、批量操作
执行批量插入、更新、删除或合并,并包含相关子项。
connection.BulkInsert(orders, order => order.Items)
.BulkInsert(invoices, invoice => invoice.Items)
.BulkMerge(shippingAddresses);
4、附加批量操作
使用 Lambda 表达式,基于最近一次的批量操作或后续批量操作的实体执行批量操作。
connection.BulkInsert(orders)
.AlsoInsert(order => order.Items)
.AlsoInsert(order => order.Invoice)
.AlsoInsert(order => order.Invoice.Items);
5、包含操作
Include 方法允许解决多个 ThenBulk 方法的问题。
connection.BulkInsert(orders)
.Include(x => x.ThenInsert(order => order.Items)
.ThenInsert(orderItem => orderItem.Metas))
.Include(x => x.ThenInsert(order => order.Invoice)
.ThenInsert(Invoice => invoice.Items));
6、支持事务
transaction.BulkInsert(orders)
.Include(x => x.ThenInsert(order => order.Items)
.ThenInsert(orderItem => orderItem.Metas))
.Include(x => x.ThenInsert(order => order.Invoice)
.ThenInsert(Invoice => invoice.Items));
04
项目地址
https://github.com/zzzprojects/Dapper-Plus
- End -
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有