public static void Test1() { Console.WriteLine("多次insert测试"); Console.ReadLine(); var count = 100000; var list = new List <Rule>(); for (int i = 0; i < count; i++) { list.Add(new Rule() { Name = "test" + i, Created = DateTime.Now, Enabled = true, Json = string.Empty, RuleType = 1, Score = 100, Updated = DateTime.Now }); } var rr = new RuleRepository(); var flist = rr.Search().OrderByDescending(b => b.Name).From(1, 2).ToList(); var ic = rr.FromSql("select count(id) from Rules").ToScalar <string>(); var max = rr.Search().Select(b => b.Id.Max()).ToFirstDefault().Id; var cou = rr.Search().Select(b => b.Id.Count()).ToFirstDefault().Id; var sum = rr.Search().Select(b => b.Id.Sum()).ToFirstDefault().Id; var avg = rr.Search().Select(b => b.Id.Avg()).ToFirstDefault().Id; rr.FromSql("TRUNCATE TABLE Rules").ToScalar(); var sw = Stopwatch.StartNew(); rr.DBContext.Insert(list); sw.Stop(); Console.WriteLine("多次insert测试完成,cost:" + sw.ElapsedMilliseconds); Console.ReadLine(); list.Clear(); for (int i = 1 * count; i < 2 * count; i++) { list.Add(new Rule() { Name = "test" + i, Created = DateTime.Now, Enabled = true, Json = string.Empty, RuleType = 1, Score = 100, Updated = DateTime.Now }); } Console.WriteLine("批量insert测试"); sw = Stopwatch.StartNew(); //rr.DBContext.BulkInsert(list); var batch = rr.DBContext.CreateBatch <Rule>(); batch.Insert(list); batch.Execute(); sw.Stop(); Console.WriteLine("批量insert测试完成,cost:" + sw.ElapsedMilliseconds); Console.ReadLine(); }