EntityConnectionStringBuilder 类
定义
为创建和管理供 EntityClient 使用的连接字符串的内容提供了一种简单的方法。Provides a simple way to create and manage the contents of connection strings used by the EntityClient.
public ref class EntityConnectionStringBuilder sealed : System::Data::Common::DbConnectionStringBuilder
public sealed class EntityConnectionStringBuilder : System.Data.Common.DbConnectionStringBuilder
type EntityConnectionStringBuilder = class
inherit DbConnectionStringBuilder
Public NotInheritable Class EntityConnectionStringBuilder
Inherits DbConnectionStringBuilder
- 继承
示例
下面的示例演示如何配合使用 EntityConnectionStringBuilder 和 SqlConnectionStringBuilder。The following example demonstrates how to use the EntityConnectionStringBuilder in conjunction with a SqlConnectionStringBuilder.
// Specify the provider name, server and database.
string providerName = "System.Data.SqlClient";
string serverName = ".";
string databaseName = "AdventureWorks";
// Initialize the connection string builder for the
// underlying provider.
SqlConnectionStringBuilder sqlBuilder =
new SqlConnectionStringBuilder();
// Set the properties for the data source.
sqlBuilder.DataSource = serverName;
sqlBuilder.InitialCatalog = databaseName;
sqlBuilder.IntegratedSecurity = true;
// Build the SqlConnection connection string.
string providerString = sqlBuilder.ToString();
// Initialize the EntityConnectionStringBuilder.
EntityConnectionStringBuilder entityBuilder =
new EntityConnectionStringBuilder();
//Set the provider name.
entityBuilder.Provider = providerName;
// Set the provider-specific connection string.
entityBuilder.ProviderConnectionString = providerString;
// Set the Metadata location.
entityBuilder.Metadata = @"res://*/AdventureWorksModel.csdl|
res://*/AdventureWorksModel.ssdl|
res://*/AdventureWorksModel.msl";
Console.WriteLine(entityBuilder.ToString());
using (EntityConnection conn =
new EntityConnection(entityBuilder.ToString()))
{
conn.Open();
Console.WriteLine("Just testing the connection.");
conn.Close();
}
' Specify the provider name, server and database.
Dim providerName As String = "System.Data.SqlClient"
Dim serverName As String = "."
Dim databaseName As String = "AdventureWorks"
' Initialize the connection string builder for the
' underlying provider.
Dim sqlBuilder As New SqlConnectionStringBuilder
' Set the properties for the data source.
sqlBuilder.DataSource = serverName
sqlBuilder.InitialCatalog = databaseName
sqlBuilder.IntegratedSecurity = True
' Build the SqlConnection connection string.
Dim providerString As String = sqlBuilder.ToString
' Initialize the EntityConnectionStringBuilder.
Dim entityBuilder As New EntityConnectionStringBuilder
'Set the provider name.
entityBuilder.Provider = providerName
' Set the provider-specific connection string.
entityBuilder.ProviderConnectionString = providerString
' Set the Metadata location to the current directory.
entityBuilder.Metadata = "res://*/AdventureWorksModel.csdl|" & _
"res://*/AdventureWorksModel.ssdl|" & _
"res://*/AdventureWorksModel.msl"
Console.WriteLine(entityBuilder.ToString)
Using conn As EntityConnection = New EntityConnection(entityBuilder.ToString)
conn.Open()
Console.WriteLine("Just testing the connection.")
conn.Close()
End Using
注解
通过连接字符串生成器,开发人员可以使用该类的属性和方法,以编程方式创建语法正确的连接字符串以及分析和重新生成现有的连接字符串。The connection string builder lets developers programmatically create syntactically correct connection strings, and parse and rebuild existing connection strings, by using properties and methods of the class. 连接字符串生成器提供了与已知关键字/值对相对应的强类型属性。The connection string builder provides strongly typed properties corresponding to the known keyword/value pairs. 必须在应用程序中创建连接字符串的开发人员可以使用 EntityConnectionStringBuilder 类生成和修改连接字符串。Developers who must create connection strings as part of applications can use the EntityConnectionStringBuilder class to build and modify connection strings.
EntityConnectionStringBuilder 对关键字/值对的有效性进行检查,其中每个关键字/值对都被公开为一个 EntityConnectionStringBuilder 属性值。The EntityConnectionStringBuilder performs checks for valid keyword/value pairs, each of which is exposed as a EntityConnectionStringBuilder property value.
备注
基础数据源的连接字符串由 ProviderConnectionString 属性提供。The connection string for the underlying data source is supplied by the ProviderConnectionString property. 对于提供的提供程序连接字符串,将不对关键字/值对的有效性进行检查。The supplied provider connection string is not checked for valid keyword/value pairs.
构造函数
EntityConnectionStringBuilder() |
初始化 EntityConnectionStringBuilder 类的新实例。Initializes a new instance of the EntityConnectionStringBuilder class. |
EntityConnectionStringBuilder(String) |
使用提供的连接字符串初始化 EntityConnectionStringBuilder 类的新实例。Initializes a new instance of the EntityConnectionStringBuilder class using the supplied connection string. |
属性
BrowsableConnectionString |
获取或设置一个值,该值指示 ConnectionString 属性是否在 Visual Studio 设计器中可见。Gets or sets a value that indicates whether the ConnectionString property is visible in Visual Studio designers. (继承自 DbConnectionStringBuilder) |
ConnectionString |
获取或设置与 DbConnectionStringBuilder 相关联的连接字符串。Gets or sets the connection string associated with the DbConnectionStringBuilder. (继承自 DbConnectionStringBuilder) |
Count |
获取属性 ConnectionString 中包含的键的当前数目。Gets the current number of keys that are contained within the ConnectionString property. (继承自 DbConnectionStringBuilder) |
IsFixedSize |
获取一个值,该值指示 EntityConnectionStringBuilder 是否具有固定大小。Gets a value that indicates whether the EntityConnectionStringBuilder has a fixed size. |
IsReadOnly |
获取一个值,该值指示 DbConnectionStringBuilder 是否为只读。Gets a value that indicates whether the DbConnectionStringBuilder is read-only. (继承自 DbConnectionStringBuilder) |
Item[String] |
获取或设置与指定的键关联的值。Gets or sets the value associated with the specified key. 在 C# 中,此属性为索引器。In C#, this property is the indexer. |
Keys |
获取包含 ICollection 中的键的 EntityConnectionStringBuilder。Gets an ICollection that contains the keys in the EntityConnectionStringBuilder. |
Metadata |
获取或设置连接字符串中的元数据位置。Gets or sets the metadata locations in the connection string. |
Name |
获取或设置配置文件中定义的节名称。Gets or sets the name of a section as defined in a configuration file. |
Provider |
获取或设置连接字符串中的基础 .NET Framework.NET Framework 数据提供程序的名称。Gets or sets the name of the underlying .NET Framework.NET Framework data provider in the connection string. |
ProviderConnectionString |
获取或设置提供程序特定的内部连接字符串。Gets or sets the inner, provider-specific connection string. |
Values |
获取一个包含 ICollection 中的值的 DbConnectionStringBuilder。Gets an ICollection that contains the values in the DbConnectionStringBuilder. (继承自 DbConnectionStringBuilder) |
方法
Add(String, Object) |
将带有指定键和值的条目添加到 DbConnectionStringBuilder 中。Adds an entry with the specified key and value into the DbConnectionStringBuilder. (继承自 DbConnectionStringBuilder) |
Clear() |
清除 EntityConnectionStringBuilder 实例的内容。Clears the contents of the EntityConnectionStringBuilder instance. |
ClearPropertyDescriptors() |
清除关联的 DbConnectionStringBuilder 上的 PropertyDescriptor 对象集合。Clears the collection of PropertyDescriptor objects on the associated DbConnectionStringBuilder. (继承自 DbConnectionStringBuilder) |
ContainsKey(String) |
确定 EntityConnectionStringBuilder 是否包含特定键。Determines whether the EntityConnectionStringBuilder contains a specific key. |
Equals(Object) |
确定指定对象是否等于当前对象。Determines whether the specified object is equal to the current object. (继承自 Object) |
EquivalentTo(DbConnectionStringBuilder) |
将此 DbConnectionStringBuilder 对象中的连接信息与提供的对象中的连接信息进行比较。Compares the connection information in this DbConnectionStringBuilder object with the connection information in the supplied object. (继承自 DbConnectionStringBuilder) |
GetHashCode() |
作为默认哈希函数。Serves as the default hash function. (继承自 Object) |
GetProperties(Hashtable) |
使用有关此 DbConnectionStringBuilder 的所有属性的信息,填充提供的 Hashtable。Fills a supplied Hashtable with information about all the properties of this DbConnectionStringBuilder. (继承自 DbConnectionStringBuilder) |
GetType() |
获取当前实例的 Type。Gets the Type of the current instance. (继承自 Object) |
MemberwiseClone() |
创建当前 Object 的浅表副本。Creates a shallow copy of the current Object. (继承自 Object) |
Remove(String) |
从 EntityConnectionStringBuilder 实例中移除具有指定的键的项。Removes the entry with the specified key from the EntityConnectionStringBuilder instance. |
ShouldSerialize(String) |
指示此 DbConnectionStringBuilder 实例中是否存在指定的键。Indicates whether the specified key exists in this DbConnectionStringBuilder instance. (继承自 DbConnectionStringBuilder) |
ToString() |
返回与此 DbConnectionStringBuilder 关联的连接字符串。Returns the connection string associated with this DbConnectionStringBuilder. (继承自 DbConnectionStringBuilder) |
TryGetValue(String, Object) |
从此 EntityConnectionStringBuilder 中检索与提供的键相对应的值。Retrieves a value corresponding to the supplied key from this EntityConnectionStringBuilder. |
显式接口实现
ICollection.CopyTo(Array, Int32) |
从特定的 ICollection 索引开始,将 Array 的元素复制到一个 Array 中。Copies the elements of the ICollection to an Array, starting at a particular Array index. (继承自 DbConnectionStringBuilder) |
ICollection.IsSynchronized |
获取一个值,该值指示是否同步对 ICollection 的访问(线程安全)。Gets a value indicating whether access to the ICollection is synchronized (thread safe). (继承自 DbConnectionStringBuilder) |
ICollection.SyncRoot |
获取可用于同步对 ICollection 的访问的对象。Gets an object that can be used to synchronize access to the ICollection. (继承自 DbConnectionStringBuilder) |
ICustomTypeDescriptor.GetAttributes() |
返回此组件实例的自定义属性的集合。Returns a collection of custom attributes for this instance of a component. (继承自 DbConnectionStringBuilder) |
ICustomTypeDescriptor.GetClassName() |
返回此组件实例的类名称。Returns the class name of this instance of a component. (继承自 DbConnectionStringBuilder) |
ICustomTypeDescriptor.GetComponentName() |
返回某个组件的此实例的名称。Returns the name of this instance of a component. (继承自 DbConnectionStringBuilder) |
ICustomTypeDescriptor.GetConverter() |
返回此组件实例的类型转换器。Returns a type converter for this instance of a component. (继承自 DbConnectionStringBuilder) |
ICustomTypeDescriptor.GetDefaultEvent() |
返回某个组件的此实例的默认事件。Returns the default event for this instance of a component. (继承自 DbConnectionStringBuilder) |
ICustomTypeDescriptor.GetDefaultProperty() |
返回此组件实例的默认属性。Returns the default property for this instance of a component. (继承自 DbConnectionStringBuilder) |
ICustomTypeDescriptor.GetEditor(Type) |
返回此组件实例的指定类型的编辑器。Returns an editor of the specified type for this instance of a component. (继承自 DbConnectionStringBuilder) |
ICustomTypeDescriptor.GetEvents() |
返回此组件实例的事件。Returns the events for this instance of a component. (继承自 DbConnectionStringBuilder) |
ICustomTypeDescriptor.GetEvents(Attribute[]) |
使用指定的属性数组作为筛选器,返回此组件实例的事件。Returns the events for this instance of a component using the specified attribute array as a filter. (继承自 DbConnectionStringBuilder) |
ICustomTypeDescriptor.GetProperties() |
返回此组件实例的属性。Returns the properties for this instance of a component. (继承自 DbConnectionStringBuilder) |
ICustomTypeDescriptor.GetProperties(Attribute[]) |
使用特性数组作为筛选器,返回此组件实例的属性。Returns the properties for this instance of a component using the attribute array as a filter. (继承自 DbConnectionStringBuilder) |
ICustomTypeDescriptor.GetPropertyOwner(PropertyDescriptor) |
返回一个对象,该对象包含指定的属性描述符所描述的属性。Returns an object that contains the property described by the specified property descriptor. (继承自 DbConnectionStringBuilder) |
IDictionary.Add(Object, Object) |
在 IDictionary 对象中添加一个带有所提供的键和值的元素。Adds an element with the provided key and value to the IDictionary object. (继承自 DbConnectionStringBuilder) |
IDictionary.Contains(Object) |
确定 IDictionary 对象是否包含具有指定键的元素。Determines whether the IDictionary object contains an element with the specified key. (继承自 DbConnectionStringBuilder) |
IDictionary.GetEnumerator() |
返回 IDictionary 对象的 IDictionaryEnumerator 对象。Returns an IDictionaryEnumerator object for the IDictionary object. (继承自 DbConnectionStringBuilder) |
IDictionary.IsFixedSize |
获取一个值,该值指示 IDictionary 对象是否具有固定大小。Gets a value indicating whether the IDictionary object has a fixed size. (继承自 DbConnectionStringBuilder) |
IDictionary.IsReadOnly |
获取一个值,该值指示 IDictionary 是否为只读。Gets a value indicating whether the IDictionary is read-only. (继承自 DbConnectionStringBuilder) |
IDictionary.Item[Object] |
获取或设置具有指定键的元素。Gets or sets the element with the specified key. (继承自 DbConnectionStringBuilder) |
IDictionary.Remove(Object) |
从 IDictionary 对象中移除具有指定键的元素。Removes the element with the specified key from the IDictionary object. (继承自 DbConnectionStringBuilder) |
IEnumerable.GetEnumerator() |
返回循环访问集合的枚举数。Returns an enumerator that iterates through a collection. (继承自 DbConnectionStringBuilder) |
扩展方法
Cast<TResult>(IEnumerable) |
将 IEnumerable 的元素强制转换为指定的类型。Casts the elements of an IEnumerable to the specified type. |
OfType<TResult>(IEnumerable) |
根据指定类型筛选 IEnumerable 的元素。Filters the elements of an IEnumerable based on a specified type. |
AsParallel(IEnumerable) |
启用查询的并行化。Enables parallelization of a query. |
AsQueryable(IEnumerable) |
将 IEnumerable 转换为 IQueryable。Converts an IEnumerable to an IQueryable. |