static void DatabaseInsert() { var sw = new System.Diagnostics.Stopwatch(); sw.Start(); var list = new List <DB.Models.Student>(); Enumerable.Range(0, 100000).ToList().ForEach(a => { list.Add(new DB.Models.Student { Name = $"strKey{a.ToString().PadLeft(7, '0')}", Address = $"strValue{a.ToString().PadLeft(7, '0')}" }); if (a % 1 == 0) { var context1 = new DB.Models.EFTestContext(); context1.Student.AddRange(list); context1.SaveChanges(); list.Clear(); Console.WriteLine($"it takes {sw.Elapsed.TotalMilliseconds}mm"); } }); var context = new DB.Models.EFTestContext(); context.SaveChanges(); list.Clear(); sw.Stop(); Console.WriteLine($"total it takes {sw.Elapsed.TotalMilliseconds}mm"); }
//1697 static List <DB.Models.Student> GetDatabaseList() { var sw = new System.Diagnostics.Stopwatch(); var context = new DB.Models.EFTestContext(); var temp = context.Student.FirstOrDefault(); sw.Start(); var list = context.Student.OrderBy(a => a.Id).Skip(0).Take(30 * 10000).ToList(); sw.Stop(); Console.WriteLine($"GetDatabaseList takes {sw.Elapsed.TotalMilliseconds}mm"); return(list); }