static void Main(string[] args) { string str = "";//"nodes=<nodes><nodesensor><nsid>112001C0000000140000</nsid><nodeid>112562600140B1</nodeid><apid>123456789</apid><sensor>000000</sensor><sensorname>无</sensorname><sensortype>0000</sensortype><sensortypename>无</sensortypename><sdvalue>0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000</sdvalue><ocvalue>0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000</ocvalue><customid></customid><unit></unit><update>2017-03-30 14:16:11</update></nodesensor></nodes>"; //ThreadPool.QueueUserWorkItem(o => //{ // while (true) // { // str = string.Format("nodes=<nodes><nodesensor><nsid>112001C0000000140000</nsid><nodeid>112562600140B1</nodeid><apid>123456789</apid><sensor>000000</sensor><sensorname>无</sensorname><sensortype>0000</sensortype><sensortypename>无</sensortypename><sdvalue>0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000</sdvalue><ocvalue>0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000</ocvalue><customid></customid><unit></unit><update>{0}</update></nodesensor></nodes>", DateTime.Now); // string mystr = HttpGet("http://localhost:13636/writedata/getdata", str); // Thread.Sleep(1000); // Console.WriteLine(mystr); // } //}); //using (MyTestEntities dbsession = new MyTestEntities()) //{ // Stopwatch watch = new Stopwatch(); // watch.Start(); // for (int i = 0; i < 100000; i++) // { // RoleInfo model = new RoleInfo // { // RoleName = "test" + i, // RoleName1 = "test" + i, // RoleName2 = "test" + i, // RoleName3 = "test" + i, // ID = i, // }; // dbsession.RoleInfo.Add(model); // dbsession.SaveChanges(); // } // watch.Stop(); // string s = watch.Elapsed.ToString(); // Console.WriteLine(s); // //Stopwatch watch1 = new Stopwatch(); // //watch1.Start(); // //for (int i = 10000; i < 20000; i++) // //{ // // RoleInfo model = new RoleInfo // // { // // RoleName = "test" + i, // // RoleName1 = "test" + i, // // RoleName2 = "test" + i, // // RoleName3 = "test" + i, // // ID = i, // // }; // // dbsession.RoleInfo.Add(model); // //} // //dbsession.SaveChanges(); // //watch1.Stop(); // //string s1 = watch1.Elapsed.ToString(); // //Console.WriteLine(s1); //} using (MyTestEntities dbsession = new MyTestEntities()) { Stopwatch watch = new Stopwatch(); watch.Start(); using (TransactionScope scope = new TransactionScope()) { for (int i = 0; i < 20000; i++) { RoleInfo model = new RoleInfo { RoleName = "test" + i, RoleName1 = "test" + i, RoleName2 = "test" + i, RoleName3 = "test" + i, ID = i, }; dbsession.RoleInfo.Add(model); } dbsession.SaveChanges(); dbsession.Database.Connection.Open(); scope.Complete(); } watch.Stop(); string s = watch.Elapsed.ToString(); Console.WriteLine(s); Stopwatch watch1 = new Stopwatch(); watch1.Start(); for (int i = 0; i < 20000; i++) { RoleInfo model = new RoleInfo { RoleName = "test" + i, RoleName1 = "test" + i, RoleName2 = "test" + i, RoleName3 = "test" + i, ID = i, }; dbsession.RoleInfo.Add(model); } dbsession.SaveChanges(); watch1.Stop(); string s1 = watch1.Elapsed.ToString(); Console.WriteLine(s1); Console.WriteLine("完成"); } Console.ReadKey(); }