public ActionResult GetProductReviewsFast(int productId = 1)
        {
            var awContext = new AdventureWorks();

              var productReviews = awContext.ProductReviews.Where(p => p.ProductID == productId).ToList();

              return View("Index");
        }
Пример #2
0
        public ActionResult Test2()
        {
            var awContext = new AdventureWorks();

              var customer = awContext.Customers.Where(x => x.CustomerID == 10).Single();

              return View("Index");
        }
        public JsonResult GetProductsFullList()
        {
            var awContext = new AdventureWorks();

              var productFullList = awContext.Products.Include(p => p.ProductInventories).ToList();

              var inventoryCount = productFullList.Count(p => p.ProductInventories.Count() > 1);

              return Json("Success!", JsonRequestBehavior.AllowGet);
        }
Пример #4
0
        public ActionResult Test1()
        {
            var awContext = new AdventureWorks();

              var customers = awContext.Customers.ToList();

              var customer = customers.Where(x => x.CustomerID == 10).Select(x => x);

              return View("Index");
        }
Пример #5
0
        public ActionResult AnyQuery()
        {
            var awContext = new AdventureWorks();

              var query = awContext.SalesOrderDetails.Any(x => x.SalesOrderHeader.Customer.Person.LastName == "Johnson");

              var queryTextModel = new QueryTextModel() { QueryText = "AnyQuery" };

              return View("QueryText", queryTextModel);
        }
        public ActionResult GetProductReviews(int productId = 1)
        {
            var awContext = new AdventureWorks();

              var product = awContext.Products.Include(p => p.ProductReviews).Single(p => p.ProductID == productId);

              var productReviews = product.ProductReviews;

              return View("Index");
        }
Пример #7
0
        public ActionResult Test3()
        {
            var awContext = new AdventureWorks();

              var customer = awContext.Customers.Where(x => x.CustomerID == 29825).First();
              var orders = customer.SalesOrderHeaders.ToList();

              var total = orders.Sum(x => x.SubTotal);

              return View("Index");
        }
        public ActionResult GetProductsBigInclude()
        {
            var awContext = new AdventureWorks();

              var productFullList = awContext.Products
            .Include(p => p.ProductVendors)
            .Include(p => p.ProductVendors.Select(pi => pi.Vendor))
            .ToList();

              return Json("Success!", JsonRequestBehavior.AllowGet);
        }
Пример #9
0
        public ActionResult DefaultIfEmptyQuery()
        {
            var awContext = new AdventureWorks();

              var person = new Person()
              {
            LastName = "Sakson"
              };

              var people = awContext.People.Where(x => x.LastName == "Sakson").ToList().DefaultIfEmpty(person);

              var queryTextModel = new QueryTextModel() { QueryText = people.First().LastName };

              return View("QueryText", queryTextModel);
        }
Пример #10
0
        public ActionResult EagerLoadQuery(int id)
        {
            // 51739
              var awContext = new AdventureWorks();
              var query =   awContext.SalesOrderHeaders
                    .Where(x => x.SalesOrderID == id)
                    .Include(x => x.SalesOrderDetails)
                    .FirstOrDefault();

              var salesOrderDetails = query.SalesOrderDetails.Where(x => x.UnitPrice > 100).ToList();

              var queryTextModel = new QueryTextModel() { QueryText = "EagerLoadQuery" };

              return View("QueryText", queryTextModel);
        }
Пример #11
0
        public ActionResult EagerLoadForEachQuery()
        {
            var awContext = new AdventureWorks();
              var query = awContext.SalesOrderHeaders
                  .Include(x => x.SalesOrderDetails)
                  .Take(1000);

              var totalUnitPrice = 0m;

              foreach (var order in query)
              {
            foreach (var detail in order.SalesOrderDetails)
            {
              totalUnitPrice += detail.UnitPrice;
            }
              }

              var queryTextModel = new QueryTextModel() { QueryText = "LazyLoadForEachQuery" };

              return View("QueryText", queryTextModel);
        }
Пример #12
0
        public ActionResult SingleQuery()
        {
            var awContext = new AdventureWorks();

              var query = awContext.SalesOrderDetails.Single(x => x.SalesOrderHeader.Customer.Person.LastName == "Sacksteder");

              var queryTextModel = new QueryTextModel() { QueryText = "SingleQuery" };

              return View("QueryText", queryTextModel);
        }
Пример #13
0
        public ActionResult SeeEFQueryWithToString()
        {
            var awContext = new AdventureWorks();

              var query =   awContext.Customers
                    .Where(x => x.Person.LastName == "Johnson")
                    .Include(x => x.SalesOrderHeaders)
                    .Include(x => x.Person);

              var queryTextModel = new QueryTextModel() { QueryText = query.ToString() };

              return View("QueryText", queryTextModel);
        }
Пример #14
0
        public ActionResult LazyLoadDisposedContextQuery()
        {
            SalesOrderHeader query;
              var queryTextModel = new QueryTextModel();

              using (var awContext = new AdventureWorks())
              {
            query = awContext.SalesOrderHeaders
                .Where(x => x.SalesOrderID == 51739)
                .FirstOrDefault();
              }

              try
              {
            var salesOrderDetail = query.SalesOrderDetails.Where(x => x.UnitPrice > 100).ToList();
              }
              catch(Exception ex)
              {
            queryTextModel.QueryText = ex.Message;

            return View("QueryText", queryTextModel);
              }

              queryTextModel.QueryText = "Never going to get here.";

              return View("QueryText", queryTextModel);
        }
        public ActionResult InsertProductReviews(int count, int productId = 1)
        {
            var awContext = new AdventureWorks();

              var timer = Stopwatch.StartNew();

              for (var i = 0; i < count; i++)
              {
            awContext.ProductReviews.Add(new ProductReview()
            {
              Comments = "test",
              EmailAddress = "*****@*****.**",
              ProductID = productId,
              ModifiedDate = DateTime.Now,
              Rating = 3,
              ReviewDate = DateTime.Now.AddDays(5),
              ReviewerName = "John Wiegert"
            });
              }

              awContext.SaveChanges();

              timer.Stop();
              var time = timer.Elapsed;

              return View("Index", (object)time.ToString());
        }
        // GET: Optimization
        public ActionResult GetProductsList()
        {
            var awContext = new AdventureWorks();

              var productList = awContext.Products.Select(p => new ProductListModel()
              {
            Name = p.Name,
            ListPrice = p.ListPrice,
            ProductID = p.ProductID,
            InventoryCount = p.ProductInventories.Count()
              }).ToList();

              var inventoryCount = productList.Count(p => p.InventoryCount > 1);

              return Json("Success!", JsonRequestBehavior.AllowGet);
        }
        public ActionResult GetTransactionHistoryNoChangesList()
        {
            var awContext = new AdventureWorks();
              var timer = Stopwatch.StartNew();

              var productFullList = awContext.TransactionHistories.AsNoTracking().ToList();

              timer.Stop();
              var time = timer.Elapsed;

              return Json("Success!", JsonRequestBehavior.AllowGet);
        }
        public ActionResult UpdateProductsList()
        {
            var awContext = new AdventureWorks();
              awContext.Configuration.AutoDetectChangesEnabled = true;

              var productFullList = awContext.Products.Take(2).ToList();
              var random = new Random();

              foreach (var product in productFullList)
              {
            product.Weight = random.Next();
              }

              awContext.SaveChanges();

              return Json("Success!", JsonRequestBehavior.AllowGet);
        }
        public ActionResult InsertProductReviewsFast(int count, int commitCount)
        {
            var awContext = new AdventureWorks();

              var firstProduct = awContext.Products.Select(p => p.ProductID).First();

              var timer = Stopwatch.StartNew();
              awContext.Configuration.AutoDetectChangesEnabled = false;
              awContext.Configuration.ValidateOnSaveEnabled = false;

              for (var i = 0; i < count; i++)
              {
            awContext.ProductReviews.Add(new ProductReview()
            {
              Comments = "test",
              EmailAddress = "*****@*****.**",
              ProductID = firstProduct,
              ModifiedDate = DateTime.Now,
              Rating = 3,
              ReviewDate = DateTime.Now.AddDays(5),
              ReviewerName = "John Wiegert"
            });

            if (i % commitCount == 0)
            {
              awContext.SaveChanges();
            }
              }

              awContext.SaveChanges();

              timer.Stop();
              var time = timer.Elapsed;

              return View("Index", (object)time.ToString());
        }
Пример #20
0
        public ActionResult IncludeQuery()
        {
            var awContext = new AdventureWorks();

              var query =   awContext.SalesOrderDetails
                    .Where(x => x.SalesOrderHeader.Customer.Person.LastName == "Johnson")
                    .Include(x => x.SalesOrderHeader)
                    .Include(x => x.SalesOrderHeader.Customer.Person)
                    .Include(x => x.SalesOrderHeader.Customer.Person.PersonPhones)
                    .Include(x => x.SalesOrderHeader.Customer.Person.EmailAddresses).ToList();

              var queryTextModel = new QueryTextModel() { QueryText = "IncludeQuery" };

              return View("QueryText", queryTextModel);
        }
Пример #21
0
        public ActionResult EFCasingQuery()
        {
            var awContext = new AdventureWorks();

              var lower = awContext.People.Where(x => x.LastName == "Johnson").ToList().Count;
              var upper = awContext.People.Where(x => x.LastName == "JOHNSON").ToList().Count;
              var mixed = awContext.People.Where(x => x.LastName == "JoHnSON").ToList().Count;

              var queryTextModel = new QueryTextModel() { QueryText = "EFCasingQuery" };

              return View("QueryText", queryTextModel);
        }
        public ActionResult Index()
        {
            var awContext = new AdventureWorks();

              var products = awContext.Products.Take(2).ToList();

              return View();
        }