示例#1
0
        private void TransactionTest2()
        {
            var selectOperation = new TextQueryOperation("SELECT [Key] FROM [dbo].[Workle.Users] WHERE [Id]=@id", new {
                id = 1
            }, "global", "users");

            while (true)
            {
                using (DbOperationScope outer = new DbOperationScope())
                {
                    Console.WriteLine("Select => {0}",
                                      outer.Execute(selectOperation).Scalar <Guid>());
                }
                Thread.Sleep(2400);
            }
        }
示例#2
0
        public void TransactionTest()
        {
            var selectOperation = new TextQueryOperation("SELECT [Key] FROM [dbo].[Workle.Users] WHERE [Id]=@id", new {
                id = 1
            }, "global", "users");

            while (true)
            {
                using (DbOperationScope outer = new DbOperationScope())
                {
                    outer.IsolationLevel = System.Data.IsolationLevel.RepeatableRead;

                    Guid currentKey = outer.Execute(selectOperation).Scalar <Guid>();
                    Console.WriteLine("Thread {0}, Current => {1}",
                                      Thread.CurrentThread.ManagedThreadId, currentKey);

                    var key             = Guid.NewGuid();
                    var updateOperation = new TextModifyOperation("UPDATE [dbo].[Workle.Users] SET [Key]=@key WHERE [Id]=@id AND [Key]=@current",
                                                                  new {
                        id      = 1,
                        key     = key,
                        current = currentKey
                    }, "users");

                    Console.WriteLine("Thread {0}, Key changed to {1}, {2} rows affected",
                                      Thread.CurrentThread.ManagedThreadId, key, outer.Execute(updateOperation));

                    Thread.Sleep(4000);

                    Console.WriteLine("Thread {0}, Updated => {1}\n",
                                      Thread.CurrentThread.ManagedThreadId,
                                      outer.Execute(selectOperation).Scalar <Guid>());

                    outer.Commit();
                }
            }
        }