DbContext DbContext DbContext Constructors

Definition

Overloads

DbContext() 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) DbContext(DbCompiledModel) 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(String) DbContext(String) 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(DbConnection, Boolean) DbContext(DbConnection, Boolean) 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(ObjectContext, Boolean) DbContext(ObjectContext, Boolean)

Constructs a new context instance around an existing ObjectContext.

DbContext(ObjectContext, Boolean) DbContext(ObjectContext, Boolean)

Constructs a new context instance around an existing ObjectContext.

An existing ObjectContext to wrap with the new context.If set to true the ObjectContext is disposed when the DbContext is disposed, otherwise the caller must dispose the connection.
DbContext(String, DbCompiledModel) DbContext(String, DbCompiledModel) 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(DbConnection, DbCompiledModel, Boolean) DbContext(DbConnection, DbCompiledModel, Boolean) 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() 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.

[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")]
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Reliability", "CA2000:Dispose objects before losing scope")]
protected DbContext ();
Protected Sub New ()

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

[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Reliability", "CA2000:Dispose objects before losing scope")]
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")]
protected DbContext (System.Data.Entity.Infrastructure.DbCompiledModel model);
new System.Data.Entity.DbContext : System.Data.Entity.Infrastructure.DbCompiledModel -> System.Data.Entity.DbContext
Protected Sub New (model As DbCompiledModel)

Parameters

model
DbCompiledModel DbCompiledModel DbCompiledModel

The model that will back this context.

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

[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Reliability", "CA2000:Dispose objects before losing scope")]
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")]
public DbContext (string nameOrConnectionString);
new System.Data.Entity.DbContext : string -> System.Data.Entity.DbContext
Public Sub New (nameOrConnectionString As String)

Parameters

nameOrConnectionString
String String String

Either the database name or a connection string.

DbContext(DbConnection, Boolean) DbContext(DbConnection, Boolean) 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.

[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Reliability", "CA2000:Dispose objects before losing scope")]
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")]
public DbContext (System.Data.Common.DbConnection existingConnection, bool contextOwnsConnection);
new System.Data.Entity.DbContext : System.Data.Common.DbConnection * bool -> System.Data.Entity.DbContext
Public Sub New (existingConnection As DbConnection, contextOwnsConnection As Boolean)

Parameters

existingConnection
DbConnection DbConnection DbConnection

An existing connection to use for the new context.

contextOwnsConnection
Boolean Boolean Boolean

If set to true the connection is disposed when the context is disposed, otherwise the caller must dispose the connection.

DbContext(ObjectContext, Boolean) DbContext(ObjectContext, Boolean)

Constructs a new context instance around an existing ObjectContext.

public DbContext (System.Data.Entity.Core.Objects.ObjectContext objectContext, bool dbContextOwnsObjectContext);
new System.Data.Entity.DbContext : System.Data.Entity.Core.Objects.ObjectContext * bool -> System.Data.Entity.DbContext

Parameters

objectContext
ObjectContext ObjectContext ObjectContext

An existing ObjectContext to wrap with the new context.

dbContextOwnsObjectContext
Boolean Boolean Boolean

If set to true the ObjectContext is disposed when the DbContext is disposed, otherwise the caller must dispose the connection.

DbContext(ObjectContext, Boolean) DbContext(ObjectContext, Boolean)

Constructs a new context instance around an existing ObjectContext.

An existing ObjectContext to wrap with the new context.If set to true the ObjectContext is disposed when the DbContext is disposed, otherwise the caller must dispose the connection.
public DbContext (System.Data.Objects.ObjectContext objectContext, bool dbContextOwnsObjectContext);
new System.Data.Entity.DbContext : System.Data.Objects.ObjectContext * bool -> System.Data.Entity.DbContext

Parameters

dbContextOwnsObjectContext
Boolean Boolean Boolean

DbContext(String, DbCompiledModel) DbContext(String, DbCompiledModel) 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.

[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Reliability", "CA2000:Dispose objects before losing scope")]
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")]
public DbContext (string nameOrConnectionString, System.Data.Entity.Infrastructure.DbCompiledModel model);
new System.Data.Entity.DbContext : string * System.Data.Entity.Infrastructure.DbCompiledModel -> System.Data.Entity.DbContext
Public Sub New (nameOrConnectionString As String, model As DbCompiledModel)

Parameters

nameOrConnectionString
String String String

Either the database name or a connection string.

model
DbCompiledModel DbCompiledModel DbCompiledModel

The model that will back this context.

DbContext(DbConnection, DbCompiledModel, Boolean) DbContext(DbConnection, DbCompiledModel, Boolean) 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.

[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Reliability", "CA2000:Dispose objects before losing scope")]
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")]
public DbContext (System.Data.Common.DbConnection existingConnection, System.Data.Entity.Infrastructure.DbCompiledModel model, bool contextOwnsConnection);
new System.Data.Entity.DbContext : System.Data.Common.DbConnection * System.Data.Entity.Infrastructure.DbCompiledModel * bool -> System.Data.Entity.DbContext
Public Sub New (existingConnection As DbConnection, model As DbCompiledModel, contextOwnsConnection As Boolean)

Parameters

existingConnection
DbConnection DbConnection DbConnection

An existing connection to use for the new context.

model
DbCompiledModel DbCompiledModel DbCompiledModel

The model that will back this context.

contextOwnsConnection
Boolean Boolean Boolean

If set to true the connection is disposed when the context is disposed, otherwise the caller must dispose the connection.

Applies to