解决办法:

1,修改连接串,加上MultipleActiveResultSets=true

 

2, 一次性先把数据读出来

Entity Framework "There is already an open DataReader associated with this 的解决办法
var contacts = from c in db.Contact
                select c;

List results = contacts.ToList();

foreach (Contact c in results){
}
Entity Framework "There is already an open DataReader associated with this 的解决办法

提示:contacts.ToList() 的作用是强制加载contact列表,也就是先强制执行查询,再做后续处理。

 

 

 

 

 

 

一定要全部tolist不然上面查询结果不tolist循环里面tolist一样会出错,MS搞个鸡巴,弄个玩意这么难用

相关文章:

  • 2021-11-04
  • 2022-03-07
  • 2022-12-23
  • 2021-10-11
  • 2022-12-23
  • 2022-02-25
  • 2022-12-23
  • 2021-12-30
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-07-02
  • 2021-09-27
相关资源
相似解决方案