EntityConnection Constructors
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
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:
The EntityConnection instance is constructed through the parameterless constructor, or through the EntityConnection(String) constructor, which accepts a connection string. In either case the connection string might be changed multiple times before the connection is opened. Calling Open or GetMetadataWorkspace locks the metadata.
The EntityConnection instance is constructed through the EntityConnection(MetadataWorkspace, DbConnection) constructor, which accepts a MetadataWorkspace and a DbConnection. In this case the metadata is locked at construction time. No changes to the connection string are ever allowed.
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:
The EntityConnection instance is constructed through the parameterless constructor, or through the EntityConnection(String) constructor, which accepts a connection string. In either case the connection string might be changed multiple times before the connection is opened. Calling Open or GetMetadataWorkspace locks the metadata.
The EntityConnection instance is constructed through the EntityConnection(MetadataWorkspace, DbConnection) constructor, which accepts a MetadataWorkspace and a DbConnection. In this case the metadata is locked at construction time. No changes to the connection string are ever allowed.
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:
The EntityConnection instance is constructed through the parameterless constructor, or through this constructor (EntityConnection(String)), which accepts a connection string. In either case the connection string might be changed multiple times before the connection is opened. Calling Open or GetMetadataWorkspace locks the metadata.
The EntityConnection instance is constructed through the EntityConnection(MetadataWorkspace, DbConnection) constructor, which accepts a MetadataWorkspace and a DbConnection. In this case the metadata is locked at construction time. No changes to the connection string are ever allowed.
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:
The EntityConnection instance is constructed through the parameterless constructor, or through the EntityConnection(String) constructor, which accepts a connection string. In either case the connection string might be changed multiple times before the connection is opened. Calling Open or GetMetadataWorkspace locks the metadata.
The EntityConnection instance is constructed through this constructor (EntityConnection(MetadataWorkspace, DbConnection)), which accepts a MetadataWorkspace and a DbConnection. In this case the metadata is locked at construction time. No changes to the connection string are ever allowed.
When metadata is loaded, the EntityConnection verifies that the conceptual model, the storage model, and the mapping file are all present.