Esempio n. 1
0
        public static void TransactionPromotion()
        {
            var tx = new CommittableTransaction();

            Utility.DisplayTransactionInfo("TX Created", tx.TransactionInformation);

            try
            {
                var db = new StudentData();
                var s1 = new Student()
                {
                    FirstName = "Z1", LastName = "ff", Company = "fff"
                };

                db.AddStudent(s1, tx);

                var s2 = new Student()
                {
                    FirstName = "first0", LastName = "last", Company = "COM"
                };

                db.AddStudent(s2, tx);
                Utility.DisplayTransactionInfo("2nd connection enlished", tx.TransactionInformation);
                tx.Commit();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                Console.WriteLine();
                tx.Rollback();
            }
        }
Esempio n. 2
0
        public static async Task CommitTableTransactionAsync()
        {
            var tx = new CommittableTransaction();

            Utility.DisplayTransactionInfo("Tx Created", tx.TransactionInformation);

            try
            {
                var s1 = new Student()
                {
                    FirstName = "Wei", LastName = "EN", Company = "WN"
                };

                var db = new StudentData();
                await db.AddStudentAsync(s1, tx);

                //if()
                tx.Commit();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
                tx.Rollback();
            }

            Utility.DisplayTransactionInfo("Tx Completed:", tx.TransactionInformation);
        }
Esempio n. 3
0
        static async void AddStudent()
        {
            Student student = new Student()
            {
                FirstName = "ff",
                LastName  = "ss",
                Company   = "ms"
            };

            StudentData studentData = new StudentData();
            Task <int>  t           = studentData.AddStudentAsync(student);

            int num = await t;

            await CommittableSamples.CommitTableTransactionAsync();

            CommittableSamples.TransactionPromotion();
            Console.WriteLine(num);
        }