Ejemplo n.º 1
0
        /// <summary>
        /// Insert 10.000 rows using Dapper
        /// </summary>
        static void InsertThousands()
        {
            var items = GetMockedData(10000);

            using (var profiler = new Framework.Core.MiniProfiler("Test_Dapper"))
            {
                var statement = "INSERT INTO TB_PERSON(FirstName,LastName,Address,City,ZipCode,Country,Status) VALUES (@FirstName,@LastName,@Address,@City,@ZipCode,@Country,@Status)";

                using (IDbConnection db = new SqlConnection("Password=p@ssw0rd;Persist Security Info=True;User ID=sa;Initial Catalog=DB_Test;Data Source=LOCALHOST"))
                {
                    db.Open();

                    foreach (var item in items)
                    {
                        db.Execute(statement,
                                   new
                        {
                            item.FirstName,
                            item.LastName,
                            item.Address,
                            item.City,
                            item.ZipCode,
                            item.Country,
                            item.Status
                        });
                    }
                }

                var total = profiler.GetElapsedTime();

                Console.WriteLine($"Elapsed time using Dapper (INSERT): {total}");
            }
        }
        /// <summary>
        /// Insert 10.000 rows using Dapper
        /// </summary>
        private void InsertThousands()
        {
            var items = GetMockedData(Constants.TotalItems);

            using (var profiler = new Framework.Core.MiniProfiler("Test_Dapper"))
            {
                var statement = "INSERT INTO TB_PERSON(FirstName,LastName,Address,City,ZipCode,Country,Status) VALUES (@FirstName,@LastName,@Address,@City,@ZipCode,@Country,@Status)";

                using (IDbConnection db = new SqlConnection(Constants.Connection))
                {
                    db.Open();

                    foreach (var item in items)
                    {
                        db.Execute(statement,
                                   new
                        {
                            item.FirstName,
                            item.LastName,
                            item.Address,
                            item.City,
                            item.ZipCode,
                            item.Country,
                            item.Status
                        });
                    }
                }

                var total = profiler.GetElapsedTime();

                ViewBag.ElapsedTimeInsertDapper = $"Elapsed time using Dapper (INSERT): {total}";
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Get 10.000 rows using Entity Framework
        /// </summary>
        static void GetThousands()
        {
            using (var profiler = new Framework.Core.MiniProfiler("Test_EF"))
            {
                using (var context = new RepoEntities())
                {
                    var items = context.TB_Person.ToList();
                }

                var total = profiler.GetElapsedTime();

                Console.WriteLine($"Elapsed time using Entity (SELECT): {total}");
            }
        }
        /// <summary>
        /// Get 10.000 rows using Entity Framework
        /// </summary>
        private void GetThousandsEF()
        {
            using (var profiler = new Framework.Core.MiniProfiler("Test_EF"))
            {
                using (var context = new RepoEntities())
                {
                    var items = context.TB_Person.ToList();
                }

                var total = profiler.GetElapsedTime();

                ViewBag.ElapsedTimeSelectEF = $"Elapsed time using Entity (SELECT): {total}";
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Get 10.000 rows using Dapper
        /// </summary>
        static void GetThousands()
        {
            using (var profiler = new Framework.Core.MiniProfiler("Test_Dapper"))
            {
                var statement = "SELECT * FROM TB_PERSON";

                using (IDbConnection db = new SqlConnection("Password=p@ssw0rd;Persist Security Info=True;User ID=sa;Initial Catalog=DB_Test;Data Source=LOCALHOST"))
                {
                    var items = db.Query <Person>(statement).ToList();
                }

                var total = profiler.GetElapsedTime();

                Console.WriteLine($"Elapsed time using Dapper (SELECT): {total}");
            }
        }
        /// <summary>
        /// Get 10.000 rows using Dapper
        /// </summary>
        private void GetThousands()
        {
            using (var profiler = new Framework.Core.MiniProfiler("Test_Dapper"))
            {
                var statement = "SELECT * FROM TB_PERSON";

                using (IDbConnection db = new SqlConnection(Constants.Connection))
                {
                    var items = db.Query <Person>(statement).ToList();
                }

                var total = profiler.GetElapsedTime();

                ViewBag.ElapsedTimeSelectDapper = $"Elapsed time using Dapper (SELECT): {total}";
            }
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Insert 10.000 rows using EF(EDMX)
        /// </summary>
        static void InsertThousands2()
        {
            var items = GetMockedData(10000);

            using (var profiler = new Framework.Core.MiniProfiler("Test_EF"))
            {
                using (var context = new RepoEntities())
                {
                    foreach (var item in items)
                    {
                        context.TB_Person.Add(item);
                    }

                    context.SaveChanges();
                }

                var total = profiler.GetElapsedTime();

                Console.WriteLine($"Elapsed time using Entity: {total}");
            }
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Insert 10.000 rows using EF (DbContext/DbSet)
        /// </summary>
        static void InsertThousands()
        {
            var items = GetMockedData(10000);

            using (var profiler = new Framework.Core.MiniProfiler("Test_EF"))
            {
                using (var context = new DatabaseContext("Password=p@ssw0rd;Persist Security Info=True;User ID=sa;Initial Catalog=DB_Test;Data Source=LOCALHOST"))
                {
                    foreach (var item in items)
                    {
                        context.Persons.Add(item);
                    }

                    context.SaveChanges();
                }

                var total = profiler.GetElapsedTime();

                Console.WriteLine($"Elapsed time using Entity (INSERT): {total}");
            }
        }
        /// <summary>
        /// Insert 10.000 rows using EF (DbContext/DbSet)
        /// </summary>
        private void InsertThousandsEF()
        {
            var items = GetMockedDataEF(Constants.TotalItems);

            using (var profiler = new Framework.Core.MiniProfiler("Test_EF"))
            {
                using (var context = new DatabaseContext(Constants.Connection))
                {
                    foreach (var item in items)
                    {
                        context.Persons.Add(item);
                    }

                    context.SaveChanges();
                }

                var total = profiler.GetElapsedTime();

                ViewBag.ElapsedTimeInsertEF = $"Elapsed time using Entity (INSERT): {total}";
            }
        }