DbContext 构造函数 (DbConnection, Boolean)

[本页针对的是实体框架版本 6。最新版本以“实体框架”NuGet 包的形式提供。有关实体框架的更多信息,请参见 msdn.com/data/ef。]

通过现有连接来连接到数据库以构造一个新的上下文实例。 如果 contextOwnsConnection 是 false,则释放上下文时将不会释放该连接。

命名空间:  System.Data.Entity
程序集:  EntityFramework(在 EntityFramework.dll 中)

语法

声明
<SuppressMessageAttribute("Microsoft.Reliability", "CA2000:Dispose objects before losing scope")> _
<SuppressMessageAttribute("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")> _
Public Sub New ( _
    existingConnection As DbConnection, _
    contextOwnsConnection As Boolean _
)
用法
Dim existingConnection As DbConnection 
Dim contextOwnsConnection As Boolean 

Dim instance As New DbContext(existingConnection, _
    contextOwnsConnection)
[SuppressMessageAttribute("Microsoft.Reliability", "CA2000:Dispose objects before losing scope")]
[SuppressMessageAttribute("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")]
public DbContext(
    DbConnection existingConnection,
    bool contextOwnsConnection
)
[SuppressMessageAttribute(L"Microsoft.Reliability", L"CA2000:Dispose objects before losing scope")]
[SuppressMessageAttribute(L"Microsoft.Usage", L"CA2214:DoNotCallOverridableMethodsInConstructors")]
public:
DbContext(
    DbConnection^ existingConnection, 
    bool contextOwnsConnection
)
[<SuppressMessageAttribute("Microsoft.Reliability", "CA2000:Dispose objects before losing scope")>]
[<SuppressMessageAttribute("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")>]
new : 
        existingConnection:DbConnection * 
        contextOwnsConnection:bool -> DbContext
public function DbContext(
    existingConnection : DbConnection, 
    contextOwnsConnection : boolean
)

参数

  • contextOwnsConnection
    类型:System.Boolean
    如果设置为 true,则释放上下文时将释放该连接;否则调用方必须释放该连接。

请参阅

参考

DbContext 类

DbContext 重载

System.Data.Entity 命名空间