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

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

    This error happens when a new query is going to be executed while you're in inside another query. Consider you have something like this in your view

    @Html.DisplayFor(modelItem => item.Device.Name)
    

    and in your Device model you have

        public string Name
        {
            get
            {
                return String.Format("{0} {1}", Brand.BrandName, Model.ModelName);
            }
        }
    

    then since for evaluating Device.Name it requires to query its Brand and Model it will become query inside query and so the solution is to enable MutlipleActiveResultSets in your database connection string as follows:

        
    

提交回复
热议问题