There is already an open DataReader associated with this Command which must be closed first

前端 未结 18 2302
孤街浪徒
孤街浪徒 2020-11-22 01:40

I have this query and I get the error in this function:

var accounts = from account in context.Accounts
               from guranteer in account.Gurantors
           


        
18条回答
  •  渐次进展
    2020-11-22 02:07

    I dont know whether this is duplicate answer or not. If it is I am sorry. I just want to let the needy know how I solved my issue using ToList().

    In my case I got same exception for below query.

    int id = adjustmentContext.InformationRequestOrderLinks.Where(
                 item => item.OrderNumber == irOrderLinkVO.OrderNumber 
                      && item.InformationRequestId == irOrderLinkVO.InformationRequestId)
                 .Max(item => item.Id);
    

    I solved like below

    List links = 
          adjustmentContext.InformationRequestOrderLinks
               .Where(item => item.OrderNumber == irOrderLinkVO.OrderNumber 
                           && item.InformationRequestId == irOrderLinkVO.InformationRequestId)
               .ToList();
    
    int id = 0;
    
    if (links.Any())
    {
      id = links.Max(x => x.Id);
    }
    if (id == 0)
    {
    //do something here
    }
    

提交回复
热议问题