Edit

Share via


EntityConnection Constructors

Definition

Initializes a new instance of the EntityConnection class.

Overloads

EntityConnection()

Initializes a new instance of the EntityConnection class.

EntityConnection(String)

Initializes a new instance of the EntityConnection class, based on the connection string.

EntityConnection(MetadataWorkspace, DbConnection)

Initializes a new instance of the EntityConnection class with a specified MetadataWorkspace and DbConnection.

Remarks

To avoid inadvertently putting objects such as System.Data.Common.CommandTrees and ObjectContext out of sync with their metadata, EntityConnection must lock its metadata. No changes to the connection string are allowed after the metadata is locked. The following are two scenarios in which metadata is locked:

When metadata is loaded, the EntityConnection verifies that the conceptual model, the storage model, and the mapping file are all present.

For code examples, see Working with EntityClient.

EntityConnection()

Initializes a new instance of the EntityConnection class.

public:
 EntityConnection();
public EntityConnection ();
Public Sub New ()

Remarks

To avoid inadvertently putting objects such as System.Data.Common.CommandTrees and ObjectContext out of sync with their metadata, EntityConnection must lock its metadata. No changes to the connection string are allowed after the metadata is locked. The following are two scenarios in which metadata is locked:

When metadata is loaded, the EntityConnection verifies that the conceptual model, the storage model, and the mapping file are all present.

For code examples, see Working with EntityClient.

Applies to

EntityConnection(String)

Initializes a new instance of the EntityConnection class, based on the connection string.

public:
 EntityConnection(System::String ^ connectionString);
public EntityConnection (string connectionString);
new System.Data.EntityClient.EntityConnection : string -> System.Data.EntityClient.EntityConnection
Public Sub New (connectionString As String)

Parameters

connectionString
String

The provider-specific connection string.

Exceptions

An invalid connection string keyword has been provided, or a required connection string keyword has not been provided.

Remarks

The Entity Data Model tools generate a named connection string that is stored in the application's configuration file. This named connection string can be supplied in place of the connectionString parameter when you instantiate the EntityConnection class.

To avoid inadvertently putting objects System.Data.Common.CommandTrees and ObjectContext out of sync with their metadata, EntityConnection must lock its metadata. No changes to the connection string are allowed after the metadata is locked. The following are two scenarios in which metadata is locked:

When metadata is loaded, the EntityConnection verifies that the conceptual model, the storage model, and the mapping file are all present.

For code examples, see Working with EntityClient.

Applies to

EntityConnection(MetadataWorkspace, DbConnection)

Initializes a new instance of the EntityConnection class with a specified MetadataWorkspace and DbConnection.

public:
 EntityConnection(System::Data::Metadata::Edm::MetadataWorkspace ^ workspace, System::Data::Common::DbConnection ^ connection);
public EntityConnection (System.Data.Metadata.Edm.MetadataWorkspace workspace, System.Data.Common.DbConnection connection);
new System.Data.EntityClient.EntityConnection : System.Data.Metadata.Edm.MetadataWorkspace * System.Data.Common.DbConnection -> System.Data.EntityClient.EntityConnection
Public Sub New (workspace As MetadataWorkspace, connection As DbConnection)

Parameters

workspace
MetadataWorkspace

A MetadataWorkspace to be associated with this EntityConnection.

connection
DbConnection

The underlying data source connection for this EntityConnection object.

Exceptions

The workspace or connection parameter is null.

The conceptual model is missing from the workspace.

-or-

The mapping file is missing from the workspace.

-or-

The storage model is missing from the workspace.

-or-

The connection is not in a closed state.

The connection is not from an ADO.NET Entity Framework-compatible provider.

Remarks

This constructor enables you to create an EntityConnection from metadata that is not from a file on a disk or from an embedded resource in an assembly.

To avoid inadvertently putting objects such as System.Data.Common.CommandTrees and ObjectContext out of sync with their metadata, the EntityConnection must lock its metadata. No changes to the connection string are allowed after the metadata is locked. The following are two scenarios in which metadata is locked:

When metadata is loaded, the EntityConnection verifies that the conceptual model, the storage model, and the mapping file are all present.

Applies to