EntityConnection 类

定义

包含对概念模型和数据源连接的引用。Contains a reference to a conceptual model and a data source connection. 此类不能被继承。This class cannot be inherited.

public ref class EntityConnection sealed : System::Data::Common::DbConnection
public sealed class EntityConnection : System.Data.Common.DbConnection
type EntityConnection = class
    inherit DbConnection
Public NotInheritable Class EntityConnection
Inherits 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.

EntityConnection(MetadataWorkspace, DbConnection)

使用指定的 和 初始化 类的新实例。Initializes a new instance of the EntityConnection class with a specified MetadataWorkspace and DbConnection.

EntityConnection(String)

基于连接字符串初始化 EntityConnection 类的新实例。Initializes a new instance of the EntityConnection class, based on the connection string.

属性

CanRaiseEvents

获取一个指示组件是否可以引发事件的值。Gets a value indicating whether the component can raise an event.

(继承自 Component)
ConnectionString

获取或设置 EntityConnection 连接字符串。Gets or sets the EntityConnection connection string.

ConnectionTimeout

获取从尝试建立连接到结束尝试并生成错误需要等待的秒数。Gets the number of seconds to wait when attempting to establish a connection before ending the attempt and generating an error.

Container

获取包含 IContainerComponentGets the IContainer that contains the Component.

(继承自 Component)
Database

获取当前数据库或将在连接打开后使用的数据库的名称。Gets the name of the current database, or the database that will be used after a connection is opened.

DataSource

获取要连接到的数据源的名称或网络地址。Gets the name or network address of the data source to connect to.

DbProviderFactory

获取此 DbProviderFactoryDbConnectionGets the DbProviderFactory for this DbConnection.

(继承自 DbConnection)
DesignMode

获取一个值,用以指示 Component 当前是否处于设计模式。Gets a value that indicates whether the Component is currently in design mode.

(继承自 Component)
Events

获取附加到此 Component 的事件处理程序的列表。Gets the list of event handlers that are attached to this Component.

(继承自 Component)
ServerVersion

获取一个字符串,该字符串包含客户端连接到的数据源的版本。Gets a string that contains the version of the data source to which the client is connected.

Site

获取或设置 ComponentISiteGets or sets the ISite of the Component.

(继承自 Component)
State

如果 ConnectionState 打开,则获取基础提供程序的 EntityConnection 属性。Gets the ConnectionState property of the underlying provider if the EntityConnection is open. 否则返回 ClosedOtherwise, returns Closed.

StoreConnection

提供对 EntityConnection 对象使用的基础数据源连接的访问。Provides access to the underlying data source connection that is used by the EntityConnection object.

方法

BeginDbTransaction(IsolationLevel)

在派生类中重写时,启动数据库事务。When overridden in a derived class, starts a database transaction.

(继承自 DbConnection)
BeginDbTransactionAsync(IsolationLevel, CancellationToken)

异步启动数据库事务。Asynchronously starts a database transaction.

(继承自 DbConnection)
BeginTransaction()

使用基础提供程序开始一个事务。Begins a transaction by using the underlying provider.

BeginTransaction(IsolationLevel)

使用基础提供程序开始一个具有指定隔离级别的事务。Begins a transaction with the specified isolation level by using the underlying provider.

BeginTransactionAsync(CancellationToken)

异步开始数据库事务。Asynchronously begins a database transaction.

(继承自 DbConnection)
BeginTransactionAsync(IsolationLevel, CancellationToken)

异步开始数据库事务。Asynchronously begins a database transaction.

(继承自 DbConnection)
ChangeDatabase(String)

不支持。Not supported.

ChangeDatabaseAsync(String, CancellationToken)

为打开的连接对象异步更改当前数据库。Asynchronously changes the current database for an open connection.

(继承自 DbConnection)
Close()

关闭与数据库之间的连接。Closes the connection to the database.

CloseAsync()

异步关闭与数据库之间的连接。Asynchronously closes the connection to the database.

(继承自 DbConnection)
CreateCommand()

EntityCommand 设置为此 Connection 的情况下创建 EntityConnection 的新实例。Creates a new instance of an EntityCommand, with the Connection set to this EntityConnection.

CreateDbCommand()

在派生类中重写时,创建并返回与当前连接关联的 DbCommand 对象。When overridden in a derived class, creates and returns a DbCommand object associated with the current connection.

(继承自 DbConnection)
CreateObjRef(Type)

创建一个对象,该对象包含生成用于与远程对象进行通信的代理所需的全部相关信息。Creates an object that contains all the relevant information required to generate a proxy used to communicate with a remote object.

(继承自 MarshalByRefObject)
Dispose()

执行与释放或重置非托管资源关联的应用程序定义的任务。Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

(继承自 DbConnection)
Dispose(Boolean)

释放由 DbConnection 占用的非托管资源,还可以另外再释放托管资源。Releases the unmanaged resources used by the DbConnection and optionally releases the managed resources.

(继承自 DbConnection)
DisposeAsync()

异步处置连接对象。Asynchronously diposes the connection object.

(继承自 DbConnection)
EnlistTransaction(Transaction)

在指定的事务中登记此 EntityConnectionEnlists this EntityConnection in the specified transaction.

Equals(Object)

确定指定对象是否等于当前对象。Determines whether the specified object is equal to the current object.

(继承自 Object)
GetHashCode()

作为默认哈希函数。Serves as the default hash function.

(继承自 Object)
GetLifetimeService()

检索控制此实例的生存期策略的当前生存期服务对象。Retrieves the current lifetime service object that controls the lifetime policy for this instance.

(继承自 MarshalByRefObject)
GetMetadataWorkspace()

返回与此 MetadataWorkspace 关联的 EntityConnectionReturns the MetadataWorkspace associated with this EntityConnection.

GetSchema()

返回此 DbConnection 的数据源的架构信息。Returns schema information for the data source of this DbConnection.

(继承自 DbConnection)
GetSchema(String)

通过使用架构名称的指定字符串,返回此 DbConnection 的数据源的架构信息。Returns schema information for the data source of this DbConnection using the specified string for the schema name.

(继承自 DbConnection)
GetSchema(String, String[])

通过使用指定字符串作为架构名称,指定字符串数组作为限制值,返回此 DbConnection 的数据源的架构信息。Returns schema information for the data source of this DbConnection using the specified string for the schema name and the specified string array for the restriction values.

(继承自 DbConnection)
GetSchemaAsync(CancellationToken)

这是 GetSchema() 的异步版本。This is an asynchronous version of GetSchema(). 提供程序应使用合适的实现进行重写。Providers should override with an appropriate implementation. 可以选择接受 cancellationTokenThe cancellationToken can optionally be honored. 默认实现调用同步 GetSchema() 调用并返回已完成任务。The default implementation invokes the synchronous GetSchema() call and returns a completed task. 如果传递到已取消 cancellationToken,则默认实现将返回已取消的任务。The default implementation will return a cancelled task if passed an already cancelled cancellationToken. GetSchema() 引发的异常将通过任务异常属性传递。Exceptions thrown by GetSchema() will be communicated via the returned Task Exception property.

(继承自 DbConnection)
GetSchemaAsync(String, CancellationToken)

这是 GetSchema(String) 的异步版本。This is the asynchronous version of GetSchema(String). 提供程序应使用合适的实现进行重写。Providers should override with an appropriate implementation. 可以选择接受 cancellationTokenThe cancellationToken can optionally be honored. 默认实现调用同步 GetSchema(String) 调用并返回已完成任务。The default implementation invokes the synchronous GetSchema(String) call and returns a completed task. 如果传递到已取消 cancellationToken,则默认实现将返回已取消的任务。The default implementation will return a cancelled task if passed an already cancelled cancellationToken. GetSchema(String) 引发的异常将通过任务异常属性传递。Exceptions thrown by GetSchema(String) will be communicated via the returned Task Exception property.

(继承自 DbConnection)
GetSchemaAsync(String, String[], CancellationToken)

这是 GetSchema(String, String[]) 的异步版本。This is the asynchronous version of GetSchema(String, String[]). 提供程序应使用合适的实现进行重写。Providers should override with an appropriate implementation. 可以选择接受 cancellationTokenThe cancellationToken can optionally be honored. 默认实现调用同步 GetSchema(String, String[]) 调用并返回已完成任务。The default implementation invokes the synchronous GetSchema(String, String[]) call and returns a completed task. 如果传递到已取消 cancellationToken,则默认实现将返回已取消的任务。The default implementation will return a cancelled task if passed an already cancelled cancellationToken. GetSchema(String, String[]) 引发的异常将通过任务异常属性传递。Exceptions thrown by GetSchema(String, String[]) will be communicated via the returned Task Exception property.

(继承自 DbConnection)
GetService(Type)

返回一个对象,该对象表示由 Component 或它的 Container 提供的服务。Returns an object that represents a service provided by the Component or by its Container.

(继承自 Component)
GetType()

获取当前实例的 TypeGets the Type of the current instance.

(继承自 Object)
InitializeLifetimeService()

获取生存期服务对象来控制此实例的生存期策略。Obtains a lifetime service object to control the lifetime policy for this instance.

(继承自 MarshalByRefObject)
MemberwiseClone()

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

(继承自 Object)
MemberwiseClone(Boolean)

创建当前 MarshalByRefObject 对象的浅表副本。Creates a shallow copy of the current MarshalByRefObject object.

(继承自 MarshalByRefObject)
OnStateChange(StateChangeEventArgs)

引发 StateChange 事件。Raises the StateChange event.

(继承自 DbConnection)
Open()

通过调用基础数据提供程序的 Open 方法,建立与数据源的连接。Establishes a connection to the data source by calling the underlying data provider's Open method.

OpenAsync()

Open()的异步版本,打开由 ConnectionString指定的设置的数据库连接。An asynchronous version of Open(), which opens a database connection with the settings specified by the ConnectionString. 此方法通过 CancellationToken.None 调用虚拟方法 OpenAsync(CancellationToken)This method invokes the virtual method OpenAsync(CancellationToken) with CancellationToken.None.

(继承自 DbConnection)
OpenAsync(CancellationToken)

这是 Open() 的异步版本。This is the asynchronous version of Open(). 提供程序应使用合适的实现进行重写。Providers should override with an appropriate implementation. 可选择性接受取消标记。The cancellation token can optionally be honored.

默认实现调用同步 Open() 调用并返回已完成任务。The default implementation invokes the synchronous Open() call and returns a completed task. 如果传递到已取消的取消标记,则默认实现将返回已取消的 cancellationToken。The default implementation will return a cancelled task if passed an already cancelled cancellationToken. Open 引发的异常将通过返回的任务异常属性传递。Exceptions thrown by Open will be communicated via the returned Task Exception property.

在返回的任务完成前,不要调用 DbConnection 对象的其他方法和属性。Do not invoke other methods and properties of the DbConnection object until the returned Task is complete.

(继承自 DbConnection)
ToString()

返回包含 Component 的名称的 String(如果有)。Returns a String containing the name of the Component, if any. 不应重写此方法。This method should not be overridden.

(继承自 Component)

事件

Disposed

在通过调用 Dispose() 方法释放组件时发生。Occurs when the component is disposed by a call to the Dispose() method.

(继承自 Component)
StateChange

当连接状态改变时发生。Occurs when the state of the connection changes.

(继承自 DbConnection)

显式接口实现

IDbConnection.BeginTransaction()

开始一项数据库事务。Begins a database transaction.

(继承自 DbConnection)
IDbConnection.BeginTransaction(IsolationLevel)

以指定的隔离级别启动数据库事务。Begins a database transaction with the specified isolation level.

(继承自 DbConnection)
IDbConnection.CreateCommand()

创建并返回与当前连接关联的 DbCommand 对象。Creates and returns a DbCommand object that is associated with the current connection.

(继承自 DbConnection)

适用于

另请参阅