DataRabbit 轻量的数据访问框架(15)-- IOrmAccesser的BatchInsert批量插入!

DataRabbit3.0为ORM访问器提供了批量插入的功能,其方法定义如下:
/// <summary>
/// BatchInsert批量插入一组记录。忽略所有Blob字段。
/// </summary>
void BatchInsert(IList < EntityType > entityList);
当我们需要一次性向同一Table中插入大量(如千条以上)的记录时,使用BatchInsert方法可以显著的提供性能。
我们还是以DataRabbit 轻量的数据访问框架(14)-- DataRabbit 3.0 与 Linq to sql 性能比较 一文中的例子来看看性能的变化。
在前文的例子中,我们是这样插入1000条记录的:
for ( int i = 2000 ;i < 3000 ;i ++ )
{
accesser.Insert(
new LinqTest.MyOrm.Customer(i, " Peng " , 434100 ));
}

使用BatchInsert方法,我们可以这样做:

IList < LinqTest.MyOrm.Customer > cusList = new List < LinqTest.MyOrm.Customer > ();
for ( int i = 2000 ;i < 3000 ;i ++ )
{
cusList.Add(
new LinqTest.MyOrm.Customer(i, " Peng " , 434100 ));
}
accesser.BatchInsert(cusList);

下面是测试的性能结果比较:

性能提升了24倍之多,这个结果还是非常不错的,所以大批量插入Entity时,推荐使用BatchInsert方法。

注意,BatchInsert方法在批量插入数据时将忽略所有的Blob字段。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值