您的位置:首页 > 其它

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

2007-08-13 11:53 531 查看
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字段。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐