场景:例如需要处理数据库大量的数据,先查询出来,然后操作数据,然后1000条合成1批次,然后再插入到另外一张表。
作用:数据流批处理,多核操作增加效率,批处理改变单个插入为批量插入增加效率
定义数据Model
1 public class Employee 2 { 3 public int EmployeeID { get; set; } 4 public string LastName { get; set; } 5 public string FirstName { get; set; } 6 7 // A random number generator that helps tp generate 8 // Employee property values. 9 static Random rand = new Random(42); 10 11 // Possible random first names. 12 static readonly string[] firstNames = { "Tom", "Mike", "Ruth", "Bob", "John" }; 13 // Possible random last names. 14 static readonly string[] lastNames = { "Jones", "Smith", "Johnson", "Walker" }; 15 16 // Creates an Employee object that contains random 17 // property values. 18 public static Employee Random() 19 { 20 return new Employee 21 { 22 EmployeeID = -1, 23 LastName = lastNames[rand.Next() % lastNames.Length], 24 FirstName = firstNames[rand.Next() % firstNames.Length] 25 }; 26 } 27 }