Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Version 1: SqlServer Timeout Exception with .ToList()
- var withdrawals = (from order in orderDc.Orders
- where order.Status == (int) OrderStatus.Delivered && order.IsAdminOrder != true && order.DeliveryDate >= fromDt && order.DeliveryDate <= toDt
- group order by order.SystemId
- into wdResult
- select new PriceModel()
- {
- Price = wdResult.Sum(q => q.WholesalePrice.GetValueOrDefault()),
- OrderCnt = wdResult.Count(),
- SystemId = wdResult.Key.GetValueOrDefault()
- }).ToList();
- //Version 2: without .ToList() - executed within a second, 3 SQL queries due to no lazy loading
- var withdrawals = (from order in orderDc.Orders
- where order.Status == (int) OrderStatus.Delivered && order.IsAdminOrder != true && order.DeliveryDate >= fromDt && order.DeliveryDate <= toDt
- group order by order.SystemId
- into wdResult
- select new PriceModel()
- {
- Price = wdResult.Sum(q => q.WholesalePrice.GetValueOrDefault()),
- OrderCnt = wdResult.Count(),
- SystemId = wdResult.Key.GetValueOrDefault()
- });
- foreach(var systemid in Systems){
- var wd = withdrawals.FirstOrDefault(q => q.SystemId == allSystem.Key);
- //more code...
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement