public void Multliple_method_calls_linetotal() { using (var db = new FakeMyDbContext()) { var sods = new List <SalesOrderDetail>(); for (int i = 0; i < 10; i++) { sods.Add(new SalesOrderDetail() { SalesOrderId = 71774, ProductId = 905, OrderQty = 4, UnitPrice = 218.454m }); } db.SalesOrderDetails.AddRange(sods); using (Log.Logger.BeginTimedOperation("Calculating quick total", "Test")) { _calcLinePriceCounter.Reset(); var results = db.SalesOrderDetails .Where(sod => sod.SalesOrderId == 71774) .ToList() .Select(sod => new { sod.OrderQty, sod.UnitPrice, LineTotal = CalculateLinePrice( sod.OrderQty, sod.UnitPrice, _calcLinePriceCounter) }).ToList(); _calcLinePriceCounter.Write(); } } }
public void Multliple_method_calls_margin() { using (var db = new FakeMyDbContext()) { var sods = new List <SalesOrderDetail>(); for (int i = 0; i < 10; i++) { sods.Add(new SalesOrderDetail() { SalesOrderId = 71774, ProductId = 905, OrderQty = 4, UnitPrice = 218.454m }); } db.SalesOrderDetails.AddRange(sods); var products = new Product() { ProductId = 905, StandardCost = 199.3757m }; db.Products.Add(products); using (Log.Logger.BeginTimedOperation("Calculating margin slowly", "Test")) { _calcLinePriceCounter.Reset(); _calcLineCostCounter.Reset(); _calcMarginCounter.Reset(); var results = db.SalesOrderDetails .Where(sod => sod.SalesOrderId == 71774) .Join(db.Products, sod => sod.ProductId, product => product.ProductId, (sod, product) => new { sod, product }) .ToList() .Select(li => new { li.sod.OrderQty, li.sod.UnitPrice, li.product.StandardCost, LineTotal = CalculateLinePrice( li.sod.OrderQty, li.sod.UnitPrice, _calcLinePriceCounter), LineCost = CalculateLineCost( li.sod.OrderQty, li.product.StandardCost, _calcLineCostCounter), Margin = CalculateMargin( CalculateLineCost( li.sod.OrderQty, li.product.StandardCost, _calcLineCostCounter), CalculateLinePrice( li.sod.OrderQty, li.sod.UnitPrice, _calcLinePriceCounter), _calcMarginCounter) }).ToList(); _calcLinePriceCounter.Write(); _calcLineCostCounter.Write(); _calcMarginCounter.Write(); } } }