Share via


DbContext 建構函式 (String)

[此頁面專屬於 Entity Framework 第 6 版。最新版本可從 'Entity Framework' NuGet 套件取得。如需 Entity Framework 的詳細資訊,請參閱 msdn.com/data/ef。]

使用給定字串當做資料庫的名稱或連接字串來建構新的內容執行個體 (這是將會建立連接的資料庫)。 如需使用此方式建立連接的詳細資訊,請參閱類別註解。

命名空間:  System.Data.Entity
組件:  EntityFramework (在 EntityFramework.dll 中)

語法

'宣告
<SuppressMessageAttribute("Microsoft.Reliability", "CA2000:Dispose objects before losing scope")> _
<SuppressMessageAttribute("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")> _
Public Sub New ( _
    nameOrConnectionString As String _
)
'用途
Dim nameOrConnectionString As String 

Dim instance As New DbContext(nameOrConnectionString)
[SuppressMessageAttribute("Microsoft.Reliability", "CA2000:Dispose objects before losing scope")]
[SuppressMessageAttribute("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")]
public DbContext(
    string nameOrConnectionString
)
[SuppressMessageAttribute(L"Microsoft.Reliability", L"CA2000:Dispose objects before losing scope")]
[SuppressMessageAttribute(L"Microsoft.Usage", L"CA2214:DoNotCallOverridableMethodsInConstructors")]
public:
DbContext(
    String^ nameOrConnectionString
)
[<SuppressMessageAttribute("Microsoft.Reliability", "CA2000:Dispose objects before losing scope")>]
[<SuppressMessageAttribute("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")>]
new : 
        nameOrConnectionString:string -> DbContext
public function DbContext(
    nameOrConnectionString : String
)

參數

  • nameOrConnectionString
    類型:System.String
    資料庫名稱或連接字串。

請參閱

參考

DbContext 類別

DbContext 多載

System.Data.Entity 命名空間