实体框架:已经有一个与此命令关联的开放DataReader
我正在使用实体框架,偶尔我会得到这个错误。
EntityCommandExecutionException{"There is already an open DataReader associated with this Command which must be closed first."}
at System.Data.EntityClient.EntityCommandDefinition.ExecuteStoreCommands...即使我没有做任何手动连接管理。
这个错误间歇性地发生。
触发错误的代码(为了便于阅读而缩短):
if (critera.FromDate > x) {
t= _tEntitites.T.Where(predicate).ToList();
}
else {
t= new List<T>(_tEntitites.TA.Where(historicPredicate).ToList());
}使用Dispose模式以便每次都打开新连接。
using (_tEntitites = new TEntities(GetEntityConnection())) {
if (critera.FromDate > x) {
t= _tEntitites.T.Where(predicate).ToList();
}
else {
t= new List<T>(_tEntitites.TA.Where(historicPredicate).ToList());
}}仍有问题
如果连接已经打开,EF为什么不重用连接?
ITMISS
米脂
随时随地看视频慕课网APP