zoukankan      html  css  js  c++  java
  • 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字段。

  • 相关阅读:
    VTK 9.0.1 vtkContextDevice2D 问题
    VTK 中文
    VTK 剪切
    VTK Color Map
    VTK Camera
    VTK Light
    VTK Read Source Object
    VTK Procedural Source Object
    Qt 布局开发问题记录
    Grafana 系列 (7):圖表是否可以数据追踪 (drill down)?(转)
  • 原文地址:https://www.cnblogs.com/zhuweisky/p/853454.html
Copyright © 2011-2022 走看看