Advertisement
Guest User

Untitled

a guest
Feb 9th, 2016
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.36 KB | None | 0 0
  1. //Version 1: SqlServer Timeout Exception with .ToList()
  2.  
  3. var withdrawals = (from order in orderDc.Orders
  4. where order.Status == (int) OrderStatus.Delivered && order.IsAdminOrder != true && order.DeliveryDate >= fromDt && order.DeliveryDate <= toDt
  5. group order by order.SystemId
  6. into wdResult
  7.                     select new PriceModel()
  8.                     {
  9.                         Price = wdResult.Sum(q => q.WholesalePrice.GetValueOrDefault()),
  10.                         OrderCnt = wdResult.Count(),
  11.                         SystemId = wdResult.Key.GetValueOrDefault()
  12.                     }).ToList();
  13.  
  14.  
  15. //Version 2: without .ToList() - executed within a second, 3 SQL queries due to no lazy loading
  16.  
  17.  
  18. var withdrawals = (from order in orderDc.Orders
  19. where order.Status == (int) OrderStatus.Delivered && order.IsAdminOrder != true && order.DeliveryDate >= fromDt && order.DeliveryDate <= toDt
  20. group order by order.SystemId
  21. into wdResult
  22.                     select new PriceModel()
  23.                     {
  24.                         Price = wdResult.Sum(q => q.WholesalePrice.GetValueOrDefault()),
  25.                         OrderCnt = wdResult.Count(),
  26.                         SystemId = wdResult.Key.GetValueOrDefault()
  27.                     });
  28.  
  29. foreach(var systemid in Systems){
  30.    var wd = withdrawals.FirstOrDefault(q => q.SystemId == allSystem.Key);
  31.    //more code...
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement