public void Show()
        {
            Console.WriteLine("Example 1\n\n");
            Console.WriteLine("Example shows Query method to get strongly typed instance on an mapped object:\n\n");

            try
            {
                Console.WriteLine("Single object:");
                var employee  = _repository.GetPerson();
                var employees = _repository.GetPeople();
                ConsoleExtension.WriteObject(employee);
                Console.WriteLine("\n\nPress any buttons to show all objects:/n");
                Console.ReadKey();
                Console.WriteLine();
                ConsoleExtension.WriteObject(employees);
                Console.WriteLine();
                bool result = false;
                do
                {
                    Console.WriteLine("The question is: Which ORM is faster Dapper, Entity Framework or Linq2SQL?");
                    Console.WriteLine("Press 1 for the first, 2 for the second and 3 for the third answer:");
                    var fasterORMQuestionAnswer = Console.ReadKey().KeyChar;
                    result = new QuestionAnswerHandler(EQuestionType.FastestORM)
                             .HandleAnswer(fasterORMQuestionAnswer);
                    Console.WriteLine();
                }while (!result);
            }
            catch (Exception exception)
            {
                Console.WriteLine(ConnectionStore.ConnectionErrorProvider(exception.Message));
            }

            GetBackChooser.GetBack();
        }
Exemple #2
0
        public void Show()
        {
            Console.WriteLine("Example 7\n\n");
            Console.WriteLine("Example shows \"QueryMultiple\" method to select multiple data from db:\n\n");

            try
            {
                _initializationRepository.Initialize();
                Console.WriteLine("QueryMultiple method execution, press any key to begin:");
                Console.ReadKey();
                Console.WriteLine("\nQueryMultiple anonymous object after connecting two objects from query result:");
                try
                {
                    var multiple = _repository.GetEmployeeAndItsAddress();
                    ConsoleExtension.WriteObject(multiple);
                }
                catch (Exception exception)
                {
                    Console.WriteLine($"nQueryMultiple method has thrown an exception: \n\n{exception.Message}");
                }
            }
            catch (Exception exception)
            {
                Console.WriteLine(ConnectionStore.ConnectionErrorProvider(exception.Message));
            }

            GetBackChooser.GetBack();
        }
        public void Show()
        {
            Console.WriteLine("Example 3\n\n");
            Console.WriteLine("Example shows \"QueryFirst\" method to select data from Employee table:\n\n");

            try
            {
                Console.WriteLine("QueryFirst method execution, press any key to begin:");
                Console.ReadKey();
                Console.WriteLine();
                Console.WriteLine("I'm working, please be patient...\n");
                _repository.PopulateEmployeeWithFakeData();
                var watchDapper = new Stopwatch();
                watchDapper.Start();
                var dapperMethod = _repository.GetFirstEmployee();
                watchDapper.Stop();
                var watchLinq = new Stopwatch();
                watchLinq.Start();
                var linqMethod = _repository.GetFirstEmployeeFiltered();
                watchLinq.Stop();
                ConsoleExtension.WriteObject(dapperMethod);
                Console.WriteLine($"\nElapsed time: {watchDapper.ElapsedMilliseconds}\n");
                ConsoleExtension.WriteObject(linqMethod);
                Console.WriteLine($"\nElapsed time: {watchLinq.ElapsedMilliseconds}\n");
                bool result = false;;
                do
                {
                    Console.WriteLine("The question is: Which of two queries above was a Dapper query?");
                    Console.WriteLine("Press 1 for the first and 2 for the second answer:");
                    var dapperQuestionAnswer = Console.ReadKey().KeyChar;
                    result = new QuestionAnswerHandler(EQuestionType.QueryFirstQuestion)
                             .HandleAnswer(dapperQuestionAnswer);
                    Console.WriteLine();
                }while (!result);
                Console.WriteLine("\n");
                Console.WriteLine("Clearing db table");
                _repository.ClearAllEmployeeData();
                Console.WriteLine("Db table cleared");
                Console.WriteLine("Reinitializing db tables");
                _initializationRepository.Initialize();
                Console.WriteLine("Db tables reinitialized");
            }
            catch (Exception exception)
            {
                Console.WriteLine(ConnectionStore.ConnectionErrorProvider(exception.Message));
            }

            GetBackChooser.GetBack();
        }
Exemple #4
0
        public void Show()
        {
            Console.WriteLine("Example 4\n\n");
            Console.WriteLine("Example shows \"QueryFirstOrDefault\" method to select data from Employee Table:\n\n");

            try
            {
                Console.WriteLine("First, answer the question\n");
                bool result = false;;
                do
                {
                    Console.WriteLine("The question is: What will happen in case if we use QueryFirsOrDefault method on more than 1 records?");
                    Console.WriteLine("Press 1 if it will return null, press 2 if it will return default value of queried type and press 3 if it will return first of found records");
                    var dapperQuestionAnswer = Console.ReadKey().KeyChar;
                    result = new QuestionAnswerHandler(EQuestionType.QueryFirstOrDefaultQuestion)
                             .HandleAnswer(dapperQuestionAnswer);
                    Console.WriteLine();
                }while (!result);

                _initializationRepository.Initialize();
                Console.WriteLine("QueryFirstOrDefault method execution, press any key to begin:");
                Console.ReadKey();
                Console.WriteLine("\nFirst or default object if found more than 1 records:");
                var firstOrDefaultEmployee = _repository.GetFirstOrDefaultEmployee();
                ConsoleExtension.WriteDynamicObject(firstOrDefaultEmployee);
                Console.WriteLine("\nSecond case, press any key to proceed:");
                Console.ReadKey();
                Console.WriteLine("\n");
                Console.WriteLine("Clearing db table");
                _repository.ClearAllEmployeeData();
                Console.WriteLine("Db table cleared");
                Console.WriteLine("\nFirst or default object if no records found:");
                var firstOrDefaultEmployeeIfEmpty = _repository.GetFirstOrDefaultEmployee();
                ConsoleExtension.WriteDynamicObject(firstOrDefaultEmployeeIfEmpty);
                Console.WriteLine("Reinitializing db tables");
                _initializationRepository.Initialize();
                Console.WriteLine("Db tables reinitialized");
            }
            catch (Exception exception)
            {
                Console.WriteLine(ConnectionStore.ConnectionErrorProvider(exception.Message));
            }

            GetBackChooser.GetBack();
        }
        public void Show()
        {
            Console.WriteLine("Example 2\n\n");
            Console.WriteLine("Example shows \"Execute\" method to insert data through stored SQL DB procedure passing anonymous parameters:\n\n");

            try
            {
                Console.WriteLine("Procedure execution, press any key to begin:");
                Console.ReadKey();
                Console.WriteLine();
                var rows = _repository.GetInsertQueryRows();
                Console.WriteLine(string.Format("Number of affected rows: {0}", (rows <= 0)? 0 : rows));
            }
            catch (Exception exception)
            {
                Console.WriteLine(ConnectionStore.ConnectionErrorProvider(exception.Message));
            }

            GetBackChooser.GetBack();
        }
Exemple #6
0
        public void Show()
        {
            Console.WriteLine("Example 6\n\n");
            Console.WriteLine("Example shows \"QuerySingleOrDefault\" method to select data from Address table:\n\n");

            try
            {
                Console.WriteLine("First, answer the question\n");
                bool result = false;;
                do
                {
                    Console.WriteLine("The question is: What will happen in case if we use QuerySingleOrDefault method on more than 1 records?");
                    Console.WriteLine("Press 1 if it will return null, press 2 if it will return an exception and press 3 if it will return any single of found records");
                    var dapperQuestionAnswer = Console.ReadKey().KeyChar;
                    result = new QuestionAnswerHandler(EQuestionType.QuerySingleOrDefaultQuestion)
                             .HandleAnswer(dapperQuestionAnswer);
                    Console.WriteLine();
                }while (!result);

                _initializationRepository.Initialize();
                Console.WriteLine("QuerySingleOrDefault method execution, press any key to begin:");
                Console.ReadKey();
                Console.WriteLine("\nSingleOrDefault object if found more than 1 records:");
                try
                {
                    var singleOrDefaultIfMany = _repository.GetSingleOrDefaultAddress();
                    ConsoleExtension.WriteObject(singleOrDefaultIfMany);
                }
                catch (Exception exception)
                {
                    Console.WriteLine($"QuerySingleOrDefault method has thrown an exception: \n\n{exception.Message}");
                }
                Console.WriteLine("\nSecond case, press any key to proceed:");
                Console.ReadKey();
                Console.WriteLine("\n");
                Console.WriteLine("Clearing db table");
                _repository.ClearAllAddressData();
                Console.WriteLine("Db table cleared");
                _repository.AddSingleFakeAddress();
                Console.WriteLine("Added single fake address to Address table");
                Console.WriteLine("\nSingleOrDefault object if single record found:");
                try
                {
                    var singleOrDefault = _repository.GetSingleOrDefaultAddress();
                    ConsoleExtension.WriteObject(singleOrDefault);
                }
                catch (Exception exception)
                {
                    Console.WriteLine($"QuerySingleOrDefault method has thrown an exception: \n\n{exception.Message}");
                }
                Console.WriteLine("\nThird case, press any key to proceed:");
                Console.ReadKey();
                Console.WriteLine("\n");
                Console.WriteLine("Clearing db table");
                _repository.ClearAllAddressData();
                Console.WriteLine("Db table cleared");
                Console.WriteLine("\nSingleOrDefault object if no records found:");
                try
                {
                    var singleOrDefaultIfEmpty = _repository.GetSingleOrDefaultAddress();
                    ConsoleExtension.WriteObject(singleOrDefaultIfEmpty);
                }
                catch (Exception exception)
                {
                    Console.WriteLine($"QuerySingleOrDefault method has thrown an exception: \n\n{exception.Message}");
                }
                Console.WriteLine("\n\nReinitializing db tables");
                _initializationRepository.Initialize();
                Console.WriteLine("Db tables reinitialized");
            }
            catch (Exception exception)
            {
                Console.WriteLine(ConnectionStore.ConnectionErrorProvider(exception.Message));
            }

            GetBackChooser.GetBack();
        }