Пример #1
0
        private static void MedicalDTC()
        {
            //   using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required, TimeSpan.FromMinutes(5), TransactionScopeAsyncFlowOption.Enabled))
            using (TransactionScope scope = new TransactionScope())
            {
                //   var token = TransactionInterop.GetTransmitterPropagationToken(Transaction.Current);
                MedicalContext medicalContext = new MedicalContext();
                string         sessionToken   = GetSessionTokenFromAdo();
                string         sessionToken2  = GetSessionTokenFromDbContext(medicalContext);
                medicalContext.Student.Add(new Student()
                {
                    Name = "student from medical "
                });


                var result = medicalContext.SaveChanges();

                //  var backOfficeResult = CallingBackOffice(sessionToken);
                var finanicalResult = CallingFinancial(sessionToken);

                Task.WaitAll(new Task[] { finanicalResult });

                scope.Complete();
            }
            var x = "";
        }
        public static void Logic()
        {
            MedicalContext dbContextNet = new MedicalContext();

            try
            {
                using (TransactionScope innerScope1 = new TransactionScope(TransactionScopeOption.Required, TimeSpan.FromMinutes(5), TransactionScopeAsyncFlowOption.Enabled))
                {
                    dbContextNet.Student.Add(new Student()
                    {
                        Name = "student from medical"
                    });
                    dbContextNet.SaveChanges();
                    throw new Exception();
                    innerScope1.Complete();
                    //     dbContextNet.RollBack();
                }



                var x = "";
            }
            catch (Exception ex)
            {
                // ex handling
                var sqlText = "select 1 ";



                dbContextNet.Database.ExecuteSqlCommand(sqlText);
                //    throw ex;
                var x = "";

                //  dbContextNet.Database.ExecuteSqlRaw($"EXEC sp_bindsession NULL");

                //   return false;
                //    throw;
            }
        }
Пример #3
0
 private static string GetSessionTokenFromDbContext(MedicalContext dbContextNet1)
 {
     return(dbContextNet1.Database.SqlQuery <string>(@"DECLARE @bind_token varchar(255);
                                                                 EXECUTE sp_getbindtoken @bind_token OUTPUT;
                                                                 SELECT @bind_token AS Token;  --GetSessionTokenFromDbContext ").FirstOrDefault());
 }