Force the Opening of the DataContext's Connection (LINQ)

邮差的信 提交于 2019-12-11 07:30:48

问题


When you create a datacontext, its connection is closed until you retrieve objects and it stays open when you retrieve objects in case you use deferred operators or late binding.

Is it possible (in an extension method of the datacontext of not) to force the datacontext to open its Connection without querying LINQ with LINQ or doing a fake query to the database with ExecuteQuery, ExecuteCommand, etc?

Thanks


回答1:


You can use the DataContext.Connection property to retrieve the connection, and call Open() yourself.



来源:https://stackoverflow.com/questions/2050940/force-the-opening-of-the-datacontexts-connection-linq

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!