Пример #1
0
        private void ShowUsersWithMarks()
        {
            using (var tran = new CommittableTransaction(
                       new TransactionOptions {
                IsolationLevel = IsolationLevel.ReadCommitted
            }))
            {
                try
                {
                    using (var context = new TESTDBContext())
                    {
                        var list = context.Groups.Include(x => x.Interns).ThenInclude(x => x.User);

                        foreach (var item in list)
                        {
                            Console.WriteLine(item.Name);
                            foreach (var mark in item.Interns)
                            {
                                Console.WriteLine(mark.User.FirstName + " " + mark.User.LastName);
                            }
                        }
                    }
                    tran.Commit();
                }
                catch (Exception)
                {
                    tran.Rollback();
                }
            }
        }
Пример #2
0
        private void ModifySomeUser()
        {
            using (var context = new TESTDBContext())
            {
                using (var contextTransaction = context.Database.BeginTransaction())
                {
                    try
                    {
                        Repository <Users> rep = new Repository <Users>(context);

                        //rep.Add(new Users()
                        //{
                        //    FirstName = "test",
                        //    LastName = "test",
                        //    Login = "******",
                        //    Password = "******",
                        //    DateOfBirth = Convert.ToDateTime("01/01/2000"),
                        //    Email = "*****@*****.**",
                        //    NumberPhone = "+373543543",

                        //});

                        var user = rep.FindById(6);
                        user.Email = "*****@*****.**";

                        rep.Update(user);

                        Console.WriteLine(user.FirstName + " " + user.LastName);

                        contextTransaction.Commit();
                    }
                    catch (Exception)
                    {
                        contextTransaction.Rollback();
                    }
                }
            }
        }