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

前端 未结 5 1859
太阳男子
太阳男子 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:30

    The real problem if that you are Lazy Loading the Position reference from the ApplicantPosition entity before the query ends this execution. If you want to keep the deferred execution on that scenario you can eager load the Position reference on your query like this:

    Include(o => o.applicantPosition.Select(a => a.Position));

    and on your GetApplicationPositionHistories keeps returning the IEnumerable.

    The other solution is to actually run the query on the GetApplicationPositionHistories method calling the ToList() or ToArrray() methods on the query.

提交回复
热议问题