DbContext Constructor (String, DbCompiledModel)
[This page is specific to the Entity Framework version 6. The latest version is available as the 'Entity Framework' NuGet package. For more information about Entity Framework, see msdn.com/data/ef.]
Constructs a new context instance using the given string as the name or connection string for the database to which a connection will be made, and initializes it from the given model. See the class remarks for how this is used to create a connection.
Namespace: System.Data.Entity
Assembly: EntityFramework (in EntityFramework.dll)
Syntax
'Declaration
<SuppressMessageAttribute("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")> _
<SuppressMessageAttribute("Microsoft.Reliability", "CA2000:Dispose objects before losing scope")> _
Public Sub New ( _
nameOrConnectionString As String, _
model As DbCompiledModel _
)
'Usage
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
)
Parameters
- nameOrConnectionString
Type: System.String
Either the database name or a connection string.
- model
Type: System.Data.Entity.Infrastructure.DbCompiledModel
The model that will back this context.