开发者

how to close command connection with LINQ / EF

开发者_JAVA百科

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() 
   }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜