开发者

using NerdDinner as an example, when should the DataContext be disposed

I noticed that NerdDinner doesn't dispose of the DataContext -- ever. That seems very strange to me. They have a Repository class that creates a private member of the data context, which hangs around for the lifetime of the repository class -- and who knows how long that is, since it's created at the time of the controller's construction again as a private member variable and never dereferenced. When is the controller derefe开发者_C百科renced?

I believe the issue revolves around passing IQueryable types, which must have an open connection at the time you iterate over them. But doesn't this then mean that there will be some dangling open connections?


Make the Repository itself disposable. Dispose the data context when the repository is disposed. Override Controller.Dispose and dispose the repository there. The controller is still alive when the view is executed.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜