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

前端 未结 5 1918
太阳男子
太阳男子 2021-02-06 02:58

This question is related to this:

My repository method has this code:

 public IEnumerable GetApplicationPositionHistor         


        
5条回答
  •  轮回少年
    2021-02-06 03:33

    Quick solution :

    public IEnumerable GetApplicationPositionHistories(int applicantId, int positionId)
        {
            return context.ApplicationsPositionHistory.Where(d => d.applicantPosition.ApplicantID == applicantId && d.applicantPosition.PositionID == positionId).Include(o => o.applicantPosition).ToList() ;
        }
    

    If you want to know, why this fixing your problem, read about how LINQ and deffered execution works. In few words - if you dont "force" execution of the select by "enumerating" query by ToList, it is in fact executed too late - in view. And this is causing trouble with other queries which want to use same connection.

提交回复
热议问题