Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

DbContext Constructor

 

Initializes a new instance of the DbContext class.

Namespace:   System.Data.Entity
Assembly:  EntityFramework (in EntityFramework.dll)

NameDescription
System_CAPS_protmethodDbContext()

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.

System_CAPS_protmethodDbContext(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.

System_CAPS_pubmethodDbContext(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.

System_CAPS_pubmethodDbContext(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.

System_CAPS_pubmethodDbContext(ObjectContext, Boolean)

Constructs a new context instance around an existing ObjectContext.

System_CAPS_pubmethodDbContext(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.

System_CAPS_pubmethodDbContext(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.

Return to top

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.

<SuppressMessageAttribute("Microsoft.Reliability", "CA2000:Dispose objects before losing scope")>
<SuppressMessageAttribute("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")>
Protected Sub New
Return to top

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.

<SuppressMessageAttribute("Microsoft.Reliability", "CA2000:Dispose objects before losing scope")>
<SuppressMessageAttribute("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")>
Protected Sub New (
	model As DbCompiledModel
)

Parameters

model
Type: System.Data.Entity.Infrastructure.DbCompiledModel

The model that will back this context.

Return to top

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.

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

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.

Return to top

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.

<SuppressMessageAttribute("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")>
<SuppressMessageAttribute("Microsoft.Reliability", "CA2000:Dispose objects before losing scope")>
Public Sub New (
	existingConnection As DbConnection,
	model As DbCompiledModel,
	contextOwnsConnection As Boolean
)

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.

Return to top

DbContext Constructor (ObjectContext, Boolean)

Constructs a new context instance around an existing ObjectContext.

Public Sub New (
	objectContext As ObjectContext,
	dbContextOwnsObjectContext As Boolean
)

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.

Return to top

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.

<SuppressMessageAttribute("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")>
<SuppressMessageAttribute("Microsoft.Reliability", "CA2000:Dispose objects before losing scope")>
Public Sub New (
	nameOrConnectionString As String
)

Parameters

nameOrConnectionString
Type: System.String

Either the database name or a connection string.

Return to top

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.

<SuppressMessageAttribute("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")>
<SuppressMessageAttribute("Microsoft.Reliability", "CA2000:Dispose objects before losing scope")>
Public Sub New (
	nameOrConnectionString As String,
	model As 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.

Return to top
Show: