Example #1
0
        static void Main(string[] args)
        {
            using var factory = new DbFactory(_connectionString).Create().GetAwaiter().GetResult();
            var context = factory.For <QuizDbContext>();

            Console.WriteLine("All Availible Quiz's");
            ShowAllQuiz(context);

            Console.WriteLine(new string('-', 20));

            Console.WriteLine("Provider Name of Quiz : ");
            var quizName = Console.ReadLine();

            if (!string.IsNullOrWhiteSpace(quizName))
            {
                using var factory2 = new DbFactory(_connectionString).Create(IsolationLevel.ReadCommitted).GetAwaiter().GetResult();
                var writableContext = factory2.For <QuizDbContext>();

                var quiz = new Quiz {
                    Title = quizName
                };
                writableContext.Quiz.Add(quiz);
                writableContext.SaveChanges();
                factory2.CommitTransaction();
                ShowAllQuiz(writableContext);
            }


            Console.WriteLine("Press any key to exit..");
            Console.ReadKey();
        }