DbContext Constructors

Definition

Overloads

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

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)

Constructs a new context instance around an existing ObjectContext.

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)

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)

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

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.

protected DbContext ();
[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 ()
Attributes

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.

protected DbContext (System.Data.Entity.Infrastructure.DbCompiledModel model);
[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

The model that will back this context.

Attributes

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.

public DbContext (string nameOrConnectionString);
[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

Either the database name or a connection string.

Attributes

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.

public DbContext (System.Data.Common.DbConnection existingConnection, bool contextOwnsConnection);
[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

An existing connection to use for the new context.

contextOwnsConnection
Boolean

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

Attributes

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

An existing ObjectContext to wrap with the new context.

dbContextOwnsObjectContext
Boolean

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

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

objectContext
ObjectContext
dbContextOwnsObjectContext
Boolean

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.

public DbContext (string nameOrConnectionString, System.Data.Entity.Infrastructure.DbCompiledModel model);
[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

Either the database name or a connection string.

model
DbCompiledModel

The model that will back this context.

Attributes

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.

public DbContext (System.Data.Common.DbConnection existingConnection, System.Data.Entity.Infrastructure.DbCompiledModel model, bool contextOwnsConnection);
[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

An existing connection to use for the new context.

model
DbCompiledModel

The model that will back this context.

contextOwnsConnection
Boolean

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

Attributes

Applies to