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.CommandTrees 和 ObjectContext)与其元数据失去同步,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实例是通过无参数构造函数构造的,或是通过 EntityConnection(String) 接受连接字符串的构造函数构造的。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. 调用 Open 或 GetMetadataWorkspace 锁定元数据。Calling Open or GetMetadataWorkspace locks the metadata.
EntityConnection 实例通过 EntityConnection(MetadataWorkspace, DbConnection) 构造函数进行构造,此构造函数接受 MetadataWorkspace 和 DbConnection。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.
加载元数据后,EntityConnection 验证概念性模型、存储模型和映射文件是否全部存在。When metadata is loaded, the EntityConnection verifies that the conceptual model, the storage model, and the mapping file are all present.
有关代码示例,请参阅使用 EntityClient。For 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.CommandTrees 和 ObjectContext)与其元数据失去同步,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实例是通过无参数构造函数构造的,或是通过 EntityConnection(String) 接受连接字符串的构造函数构造的。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. 调用 Open 或 GetMetadataWorkspace 锁定元数据。Calling Open or GetMetadataWorkspace locks the metadata.
EntityConnection 实例通过 EntityConnection(MetadataWorkspace, DbConnection) 构造函数进行构造,此构造函数接受 MetadataWorkspace 和 DbConnection。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.
加载元数据后,EntityConnection 验证概念性模型、存储模型和映射文件是否全部存在。When metadata is loaded, the EntityConnection verifies that the conceptual model, the storage model, and the mapping file are all present.
有关代码示例,请参阅使用 EntityClient。For 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 参数 EntityConnection 。This named connection string can be supplied in place of the connectionString parameter when you instantiate the EntityConnection class.
为了避免无意使对象(如 System.Data.Common.CommandTrees 和 ObjectContext)与其元数据失去同步,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实例通过无参数构造函数构造,或通过此构造函数构造 (EntityConnection(String)) ,该构造函数接受一个连接字符串。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. 调用 Open 或 GetMetadataWorkspace 锁定元数据。Calling Open or GetMetadataWorkspace locks the metadata.
EntityConnection 实例通过 EntityConnection(MetadataWorkspace, DbConnection) 构造函数进行构造,此构造函数接受 MetadataWorkspace 和 DbConnection。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.
加载元数据后,EntityConnection 验证概念性模型、存储模型和映射文件是否全部存在。When metadata is loaded, the EntityConnection verifies that the conceptual model, the storage model, and the mapping file are all present.
有关代码示例,请参阅使用 EntityClient。For 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 关联的 EntityConnection。A MetadataWorkspace to be associated with this EntityConnection.
- connection
- DbConnection
此 EntityConnection 对象的基础数据源连接。The underlying data source connection for this EntityConnection object.
例外
workspace 或 connection 参数为 null。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-
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.
注解
此构造函数使您可从非磁盘文件或非程序集嵌入资源的元数据创建 EntityConnection。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.
为了避免无意使对象(如 System.Data.Common.CommandTrees 和 ObjectContext)与其元数据失去同步,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实例是通过无参数构造函数构造的,或是通过 EntityConnection(String) 接受连接字符串的构造函数构造的。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. 调用 Open 或 GetMetadataWorkspace 锁定元数据。Calling Open or GetMetadataWorkspace locks the metadata.
EntityConnection 实例通过构造函数(EntityConnection(MetadataWorkspace, DbConnection))进行构造,此构造函数接受 MetadataWorkspace 和 DbConnection。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.
加载元数据后,EntityConnection 验证概念性模型、存储模型和映射文件是否全部存在。When metadata is loaded, the EntityConnection verifies that the conceptual model, the storage model, and the mapping file are all present.