working with Azure and EF I get the error message:
DataReader associated with this Command which must be closed first.
It because my queries are nested:
foreach (Element s in ElementSet.All()) {
if (somecondition) {
ElementSet.Add()
}
}
How can I load all the Elements from ElementSet and close the connection before I cycle through them with foreach?
P.S.: Apprently with SQL azure I can not set MARS in the connection string which would make the server accept multiple connections.
MARS will not use multiple connections but it will allow multiple concurrent operations over single connection. MARS was recently added to SQL Azure so you should definitely turn it on.
If you want to force EF to load all entities immediately call ToList
in your query.
foreach (Element s in ElementSet.All().ToList()) {
if (somecondition) {
ElementSet.Add()
}
}
精彩评论