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字段。
/// <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字段。
相关文章推荐
- DataRabbit 轻量的数据访问框架(15)-- IOrmAccesser的BatchInsert批量插入!
- DataRabbit 轻量的数据访问框架(03) -- IOrmAccesser(续)
- DataRabbit 轻量的数据访问框架(03) -- IOrmAccesser(续)
- DataRabbit 轻量的数据访问框架(03) -- IOrmAccesser(续)
- DataRabbit 轻量的数据访问框架(19)-- 读写分离与隔离级别
- DataRabbit 轻量的数据访问框架(14)-- DataRabbit 3.0 与 Linq to sql 性能比较
- DataRabbit 轻量的数据访问框架(02) -- IOrmAccesser
- DataRabbit 轻量的数据访问框架(05) -- ITableAccesser
- DataRabbit 轻量的数据访问框架(02) -- IOrmAccesser
- DataRabbit 轻量的数据访问框架(02) -- IOrmAccesser
- DataRabbit 轻量的数据访问框架(13)-DataRabbit 3.0 ORM性能提升
- DataRabbit 轻量的数据访问框架(14)-- DataRabbit 3.0 与 Linq to sql 性能比较
- DataRabbit 轻量的数据访问框架(12)-- 将DataRabbit融入架构
- DataRabbit 轻量的数据访问框架(05) -- ITableAccesser
- DataRabbit 轻量的数据访问框架(19)-- 读写分离与隔离级别
- DataRabbit 轻量的数据访问框架 开始学习
- DataRabbit 轻量的数据访问框架(08) -- DataRabbit 的入口点:TransactionScopeFactory和TransactionScope
- DataRabbit 轻量的数据访问框架(13)--DataRabbit 3.0 ORM性能大幅度提升!
- DataRabbit 轻量的数据访问框架(06) -- IRelationAccesser
- DataRabbit 轻量的数据访问框架(10) -- IPagerManager