Esempio n. 1
0
        private static void Single()
        {
            var t1 = new Task(() =>
            {
                for (int i = 0; i < 100; i++)
                {
                    singleDb.Insertable(new Order()
                    {
                        Name = "test", CreateTime = DateTime.Now
                    }).ExecuteCommand();
                    System.Threading.Thread.Sleep(1);
                }
            });
            var t2 = new Task(() =>
            {
                for (int i = 0; i < 100; i++)
                {
                    singleDb.Insertable(new Order()
                    {
                        Name = "test2", CreateTime = DateTime.Now
                    }).ExecuteCommand();
                    System.Threading.Thread.Sleep(10);
                }
            });
            var t3 = new Task(() =>
            {
                for (int i = 0; i < 100; i++)
                {
                    singleDb.Insertable(new Order()
                    {
                        Name = "test3", CreateTime = DateTime.Now
                    }).ExecuteCommand();
                    System.Threading.Thread.Sleep(6);
                }
            });

            t1.Start();
            t2.Start();
            t3.Start();

            Task.WaitAll(t1, t2, t3);
        }
Esempio n. 2
0
        private static void Fastest2()
        {
            var db = new SqlSugarScope(new SqlSugar.ConnectionConfig()
            {
                ConnectionString      = Config.ConnectionString,
                DbType                = DbType.SqlServer,
                IsAutoCloseConnection = true
            });

            db.CodeFirst.InitTables <Test2>();
            db.DbMaintenance.TruncateTable <Test2>();
            //用例代码
            db.Insertable(new Test2()
            {
                p = "1"
            }).ExecuteCommand();                                    //用例代码

            db.Insertable(new Test2()
            {
                p = "2", delPer = 1
            }).ExecuteCommand();                                                //用例代码

            var updateList = db.Queryable <Test2>()
                             .ToList();

            db.Fastest <Test2>().BulkCopy(updateList);

            int index = 0;

            foreach (var update in updateList)
            {
                update.p = index.ToString();

                index++;
            }

            db.Fastest <Test2>().BulkUpdate(updateList);

            Console.WriteLine("用例跑完");
        }