Question about entity structure and transactions

        public void SomeMethod1()
        {
            using (TemplateEntities ctx = new TemplateEntities())
            {
                //do something in this ctx
            }
        }

        public void SomeMethod2()
        {
            using (TemplateEntities ctx = new TemplateEntities())
            {
                //do something else in this ctx
            }
        }

        public void SomeMethod()
        {
            using (TemplateEntities ctx = new TemplateEntities())
            {
                using (TransactionScope tran = new TransactionScope())
                {
                    SomeMethod1();
                    SomeMethod2();
                    var itemToDelete= (from x in ctx.Xxx
                                    where x.Id==1
                                    select x).Single();
                    ctx.Xxx.DeleteObject(itemToDelete);
                    ctx.SaveChanges();
                    tran.Complete(); 
                }
            }
        }

What happens in SomeMethod is executed in a transaction, even if there are more contexts? I am using POCO.

+3
source share
2 answers

TransactionScope ObjectContext, , (SomeMethod) . NT . Microsoft Distributed Transaction Coordinator (MSDTC). ( ). . RPC .

0

, : . , , . , , . , .

0

Source: https://habr.com/ru/post/1771101/


All Articles