2016/09/02

[.NET] 解決 EF 錯誤: there is already an open datareader associated with this command which must be closed first

筆記錯誤解法, 供未來翻查

情境:

foreach 中又有巢狀的查詢物件條件, 造成 lazy loading 出現錯誤


錯誤訊息: 
There is already an open datareader associated with this command which must be closed first.

解法:

在使用 EF 的 connectionString 連線字串加上 MultipleActiveResultSets=true 設定即可


參考:

http://stackoverflow.com/questions/4867602/entity-framework-there-is-already-an-open-datareader-associated-with-this-comma

沒有留言: