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.


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 DbContext()

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

[SuppressMessageAttribute("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")]
[SuppressMessageAttribute("Microsoft.Reliability", "CA2000:Dispose objects before losing scope")]
public 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.

[SuppressMessageAttribute("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")]
[SuppressMessageAttribute("Microsoft.Reliability", "CA2000:Dispose objects before losing scope")]
public 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.

public DbContext(
	ObjectContext objectContext,
	bool dbContextOwnsObjectContext
)

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.

[SuppressMessageAttribute("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")]
[SuppressMessageAttribute("Microsoft.Reliability", "CA2000:Dispose objects before losing scope")]
public 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.

[SuppressMessageAttribute("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")]
[SuppressMessageAttribute("Microsoft.Reliability", "CA2000:Dispose objects before losing scope")]
public 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.