DbContext Constructor
Initializes a new instance of the DbContext class.
Assembly: EntityFramework (in EntityFramework.dll)
| Name | Description | |
|---|---|---|
![]() | DbContext() | Constructs a new context instance using conventions to create the name of the database to which a connection will be made. The by-convention name is the full name (namespace + class name) of the derived context class. See the class remarks for how this is used to create a connection. |
![]() | DbContext(DbCompiledModel^) | Constructs a new context instance using conventions to create the name of the database to which a connection will be made, and initializes it from the given model. The by-convention name is the full name (namespace + class name) of the derived context class. See the class remarks for how this is used to create a connection. |
![]() | DbContext(DbConnection^, Boolean) | Constructs a new context instance using the existing connection to connect to a database. The connection will not be disposed when the context is disposed if contextOwnsConnection is false. |
![]() | DbContext(DbConnection^, DbCompiledModel^, Boolean) | Constructs a new context instance using the existing connection to connect to a database, and initializes it from the given model. The connection will not be disposed when the context is disposed if contextOwnsConnection is false. |
![]() | DbContext(ObjectContext^, Boolean) | Constructs a new context instance around an existing ObjectContext. |
![]() | DbContext(String^) | 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. See the class remarks for how this is used to create a connection. |
![]() | DbContext(String^, DbCompiledModel^) | 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. |
DbContext Constructor ()
Constructs a new context instance using conventions to create the name of the database to which a connection will be made. The by-convention name is the full name (namespace + class name) of the derived context class. See the class remarks for how this is used to create a connection.
DbContext Constructor (DbCompiledModel^)
Constructs a new context instance using conventions to create the name of the database to which a connection will be made, and initializes it from the given model. The by-convention name is the full name (namespace + class name) of the derived context class. See the class remarks for how this is used to create a connection.
protected: [SuppressMessageAttribute("Microsoft.Reliability", "CA2000:Dispose objects before losing scope")] [SuppressMessageAttribute("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")] DbContext( DbCompiledModel^ model )
Parameters
- model
-
Type:
System.Data.Entity.Infrastructure::DbCompiledModel^
The model that will back this context.
DbContext Constructor (DbConnection^, Boolean)
Constructs a new context instance using the existing connection to connect to a database. The connection will not be disposed when the context is disposed if contextOwnsConnection is false.
public: [SuppressMessageAttribute("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")] [SuppressMessageAttribute("Microsoft.Reliability", "CA2000:Dispose objects before losing scope")] DbContext( DbConnection^ existingConnection, bool contextOwnsConnection )
Parameters
- existingConnection
-
Type:
System.Data.Common::DbConnection^
An existing connection to use for the new context.
- contextOwnsConnection
-
Type:
System::Boolean
If set to true the connection is disposed when the context is disposed, otherwise the caller must dispose the connection.
DbContext Constructor (DbConnection^, DbCompiledModel^, Boolean)
Constructs a new context instance using the existing connection to connect to a database, and initializes it from the given model. The connection will not be disposed when the context is disposed if contextOwnsConnection is false.
public: [SuppressMessageAttribute("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")] [SuppressMessageAttribute("Microsoft.Reliability", "CA2000:Dispose objects before losing scope")] DbContext( DbConnection^ existingConnection, DbCompiledModel^ model, bool contextOwnsConnection )
Parameters
- existingConnection
-
Type:
System.Data.Common::DbConnection^
An existing connection to use for the new context.
- model
-
Type:
System.Data.Entity.Infrastructure::DbCompiledModel^
The model that will back this context.
- contextOwnsConnection
-
Type:
System::Boolean
If set to true the connection is disposed when the context is disposed, otherwise the caller must dispose the connection.
DbContext Constructor (ObjectContext^, Boolean)
Constructs a new context instance around an existing ObjectContext.
Parameters
- objectContext
-
Type:
System.Data.Entity.Core.Objects::ObjectContext^
An existing ObjectContext to wrap with the new context.
- dbContextOwnsObjectContext
-
Type:
System::Boolean
If set to true the ObjectContext is disposed when the DbContext is disposed, otherwise the caller must dispose the connection.
DbContext Constructor (String^)
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. See the class remarks for how this is used to create a connection.
public: [SuppressMessageAttribute("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")] [SuppressMessageAttribute("Microsoft.Reliability", "CA2000:Dispose objects before losing scope")] DbContext( String^ nameOrConnectionString )
Parameters
- nameOrConnectionString
-
Type:
System::String^
Either the database name or a connection string.
DbContext Constructor (String^, DbCompiledModel^)
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.
public: [SuppressMessageAttribute("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")] [SuppressMessageAttribute("Microsoft.Reliability", "CA2000:Dispose objects before losing scope")] DbContext( String^ nameOrConnectionString, DbCompiledModel^ model )
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.

