EntityConnection 构造函数

定义

初始化 EntityConnection 类的新实例。Initializes a new instance of the EntityConnection class.

重载

EntityConnection()

初始化 EntityConnection 类的新实例。Initializes a new instance of the EntityConnection class.

EntityConnection(String)

基于连接字符串初始化 EntityConnection 类的新实例。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.

注解

为了避免无意使对象(如 System.Data.Common.CommandTreesObjectContext)与其元数据失去同步,EntityConnection 必须锁定对象的元数据。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:

加载元数据后,EntityConnection 验证概念性模型、存储模型和映射文件是否全部存在。When metadata is loaded, the EntityConnection verifies that the conceptual model, the storage model, and the mapping file are all present.

有关代码示例,请参阅使用 EntityClientFor code examples, see Working with EntityClient.

EntityConnection()

初始化 EntityConnection 类的新实例。Initializes a new instance of the EntityConnection class.

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

注解

为了避免无意使对象(如 System.Data.Common.CommandTreesObjectContext)与其元数据失去同步,EntityConnection 必须锁定对象的元数据。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:

加载元数据后,EntityConnection 验证概念性模型、存储模型和映射文件是否全部存在。When metadata is loaded, the EntityConnection verifies that the conceptual model, the storage model, and the mapping file are all present.

有关代码示例,请参阅使用 EntityClientFor code examples, see Working with EntityClient.

适用于

EntityConnection(String)

基于连接字符串初始化 EntityConnection 类的新实例。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)

参数

connectionString
String

提供程序特定的连接字符串。The provider-specific connection string.

例外

提供的连接字符串关键字无效,或未提供所需的连接字符串关键字。An invalid connection string keyword has been provided, or a required connection string keyword has not been provided.

注解

实体数据模型工具会生成一个名为的连接字符串,该字符串存储在应用程序的配置文件中。The Entity Data Model tools generate a named connection string that is stored in the application's configuration file. 在实例化类时,可以提供此命名连接字符串来代替 connectionString 参数 EntityConnectionThis named connection string can be supplied in place of the connectionString parameter when you instantiate the EntityConnection class.

为了避免无意使对象(如 System.Data.Common.CommandTreesObjectContext)与其元数据失去同步,EntityConnection 必须锁定对象的元数据。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:

加载元数据后,EntityConnection 验证概念性模型、存储模型和映射文件是否全部存在。When metadata is loaded, the EntityConnection verifies that the conceptual model, the storage model, and the mapping file are all present.

有关代码示例,请参阅使用 EntityClientFor code examples, see Working with EntityClient.

适用于

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)

参数

workspace
MetadataWorkspace

与此 MetadataWorkspace 关联的 EntityConnectionA MetadataWorkspace to be associated with this EntityConnection.

connection
DbConnection

EntityConnection 对象的基础数据源连接。The underlying data source connection for this EntityConnection object.

例外

workspaceconnection 参数为 nullThe 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-

connection 不处于已关闭状态。The connection is not in a closed state.

connection 并非来自与 ADO.NET Entity Framework 兼容的提供程序。The connection is not from an ADO.NET Entity Framework-compatible provider.

注解

此构造函数使您可从非磁盘文件或非程序集嵌入资源的元数据创建 EntityConnectionThis 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.

为了避免无意使对象(如 System.Data.Common.CommandTreesObjectContext)与其元数据失去同步,EntityConnection 必须锁定对象的元数据。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:

加载元数据后,EntityConnection 验证概念性模型、存储模型和映射文件是否全部存在。When metadata is loaded, the EntityConnection verifies that the conceptual model, the storage model, and the mapping file are all present.

适用于