强制打开DataContext的连接(LINQ) [英] Force the Opening of the DataContext's Connection (LINQ)

查看:209
本文介绍了强制打开DataContext的连接(LINQ)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当您创建数据文件时,它的连接会关闭,直到您检索对象,并且在您使用延迟运算符或后期绑定时检索对象时,它仍然保持打开状态。

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.

是否可能(在不是数据报文的扩展方法中)强制数据报文打开其连接,而无需使用LINQ查询LINQ或使用ExecuteQuery,ExecuteCommand等对数据库进行伪查询?

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?

感谢

推荐答案

您可以使用 DataContext.Connection 连接,然后 Open()

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

这篇关于强制打开DataContext的连接(LINQ)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆