Share via


DbContext 建構函式 (String, DbCompiledModel)

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

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

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

語法

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

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

參數

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

請參閱

參考

DbContext 類別

DbContext 多載

System.Data.Entity 命名空間