79119838

Date: 2024-10-23 22:04:19
Score: 0.5
Natty:
Report link

I changed the code like the below. Then it is working fine. I moved the commodityId condition from query1 to query2. I do not see any reason for it to be timed out because of the commodityid condition. It's just an integer column. Thanks all for your help.

        
        public virtual List<TradeView> GetTradeViewByDatesDataSourceAndCommodityId(DateTime fromDate, DateTime toDate, int commodityId, int originId, int dataSourceId)
{
    var context = GetTradeEntities();

    var query1 = (from tradeView in context.TradeViews
                  where
                         (tradeView.OriginId == originId)
                        && (tradeView.DataSourceId == dataSourceId)
                  select tradeView);
    var theList = query1.ToList();

    var query2 = (from tradeView in theList
                  where (tradeView.MonthStartDate >= fromDate)
                         && (tradeView.MonthEndDate <= toDate)
                         && (tradeView.CommodityId == commodityId)
                  select tradeView);
                           
    return query2.ToList();
} 

Reasons:
  • Blacklisted phrase (0.5): Thanks
  • Long answer (-1):
  • Has code block (-0.5):
  • Self-answer (0.5):
  • Low reputation (1):
Posted by: user965291