public static TestResult EfFastDataAccess()
        {
            List<Customer> customers = null;
            var db = new DataContext();
            db.Configuration.AutoDetectChangesEnabled = false;
            db.Configuration.EnsureTransactionsForFunctionsAndCommands = false;
            db.Configuration.LazyLoadingEnabled = false;
            db.Configuration.ProxyCreationEnabled = false;
            db.Configuration.UseDatabaseNullSemantics = false;
            db.Configuration.ValidateOnSaveEnabled = false;
            db.Customers.FirstOrDefault();
            var stopwatch = Stopwatch.StartNew();
            using (db)
            {
                for (int i = 0; i < TOTAL_TIMES; i++)
                {
                    customers = db.Customers.AsNoTracking().ToList();
                }
            }
            stopwatch.Stop();
            db = null;

            customers = null;

            return new TestResult("Entity Framework Fast", stopwatch.Elapsed);
        }
Ejemplo n.º 2
0
        public static TestResult EfDataAccess()
        {
            List<Customer> customers = null;
            var db = new DataContext();
            var stopwatch = Stopwatch.StartNew();
            using (db)
            {
                for (int i = 0; i < TOTAL_TIMES; i++)
                {
                    customers = db.Customers.ToList();
                }
            }
            stopwatch.Stop();
            db = null;
            customers = null;

            return new TestResult("Entity Framework", stopwatch.Elapsed);
        }
Ejemplo n.º 3
0
        public static void EfDataAccess()
        {
            DataContext db = new DataContext();

            string connectionString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
            List<Customer> customers = new List<Customer>();

            var startDate = DateTime.Now;
            //db.Database.Log = Console.Write;
            customers = db.Customers.ToList();
            var endDate = DateTime.Now;

            Console.WriteLine("Entity Framework");
            Console.WriteLine("Objetos Gerados: {0}", customers.Count);
            Console.WriteLine("Início: {0}", startDate);
            Console.WriteLine("Término: {0}", endDate);
            Console.WriteLine("Tempo Total: {0}", (endDate - startDate));

            customers = null;
            db.Dispose();
        }