Επεξεργασία

Κοινή χρήση μέσω


EntityConnectionStringBuilder Class

Definition

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
Inheritance
EntityConnectionStringBuilder

Examples

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

Remarks

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. Developers who must create connection strings as part of applications can use the EntityConnectionStringBuilder class to build and modify connection strings.

The EntityConnectionStringBuilder performs checks for valid keyword/value pairs, each of which is exposed as a EntityConnectionStringBuilder property value.

Note

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.

Constructors

EntityConnectionStringBuilder()

Initializes a new instance of the EntityConnectionStringBuilder class.

EntityConnectionStringBuilder(String)

Initializes a new instance of the EntityConnectionStringBuilder class using the supplied connection string.

Properties

BrowsableConnectionString

Gets or sets a value that indicates whether the ConnectionString property is visible in Visual Studio designers.

(Inherited from DbConnectionStringBuilder)
ConnectionString

Gets or sets the connection string associated with the DbConnectionStringBuilder.

(Inherited from DbConnectionStringBuilder)
Count

Gets the current number of keys that are contained within the ConnectionString property.

(Inherited from DbConnectionStringBuilder)
IsFixedSize

Gets a value that indicates whether the EntityConnectionStringBuilder has a fixed size.

IsReadOnly

Gets a value that indicates whether the DbConnectionStringBuilder is read-only.

(Inherited from DbConnectionStringBuilder)
Item[String]

Gets or sets the value associated with the specified key. In C#, this property is the indexer.

Keys

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

Gets or sets the name of the underlying .NET Framework data provider in the connection string.

ProviderConnectionString

Gets or sets the inner, provider-specific connection string.

Values

Gets an ICollection that contains the values in the DbConnectionStringBuilder.

(Inherited from DbConnectionStringBuilder)

Methods

Add(String, Object)

Adds an entry with the specified key and value into the DbConnectionStringBuilder.

(Inherited from DbConnectionStringBuilder)
Clear()

Clears the contents of the EntityConnectionStringBuilder instance.

ClearPropertyDescriptors()

Clears the collection of PropertyDescriptor objects on the associated DbConnectionStringBuilder.

(Inherited from DbConnectionStringBuilder)
ContainsKey(String)

Determines whether the EntityConnectionStringBuilder contains a specific key.

Equals(Object)

Determines whether the specified object is equal to the current object.

(Inherited from Object)
EquivalentTo(DbConnectionStringBuilder)

Compares the connection information in this DbConnectionStringBuilder object with the connection information in the supplied object.

(Inherited from DbConnectionStringBuilder)
GetHashCode()

Serves as the default hash function.

(Inherited from Object)
GetProperties(Hashtable)

Fills a supplied Hashtable with information about all the properties of this DbConnectionStringBuilder.

(Inherited from DbConnectionStringBuilder)
GetType()

Gets the Type of the current instance.

(Inherited from Object)
MemberwiseClone()

Creates a shallow copy of the current Object.

(Inherited from Object)
Remove(String)

Removes the entry with the specified key from the EntityConnectionStringBuilder instance.

ShouldSerialize(String)

Indicates whether the specified key exists in this DbConnectionStringBuilder instance.

(Inherited from DbConnectionStringBuilder)
ToString()

Returns the connection string associated with this DbConnectionStringBuilder.

(Inherited from DbConnectionStringBuilder)
TryGetValue(String, Object)

Retrieves a value corresponding to the supplied key from this EntityConnectionStringBuilder.

Explicit Interface Implementations

ICollection.CopyTo(Array, Int32)

Copies the elements of the ICollection to an Array, starting at a particular Array index.

(Inherited from DbConnectionStringBuilder)
ICollection.IsSynchronized

Gets a value indicating whether access to the ICollection is synchronized (thread safe).

(Inherited from DbConnectionStringBuilder)
ICollection.SyncRoot

Gets an object that can be used to synchronize access to the ICollection.

(Inherited from DbConnectionStringBuilder)
ICustomTypeDescriptor.GetAttributes()

Returns a collection of custom attributes for this instance of a component.

(Inherited from DbConnectionStringBuilder)
ICustomTypeDescriptor.GetClassName()

Returns the class name of this instance of a component.

(Inherited from DbConnectionStringBuilder)
ICustomTypeDescriptor.GetComponentName()

Returns the name of this instance of a component.

(Inherited from DbConnectionStringBuilder)
ICustomTypeDescriptor.GetConverter()

Returns a type converter for this instance of a component.

(Inherited from DbConnectionStringBuilder)
ICustomTypeDescriptor.GetDefaultEvent()

Returns the default event for this instance of a component.

(Inherited from DbConnectionStringBuilder)
ICustomTypeDescriptor.GetDefaultProperty()

Returns the default property for this instance of a component.

(Inherited from DbConnectionStringBuilder)
ICustomTypeDescriptor.GetEditor(Type)

Returns an editor of the specified type for this instance of a component.

(Inherited from DbConnectionStringBuilder)
ICustomTypeDescriptor.GetEvents()

Returns the events for this instance of a component.

(Inherited from DbConnectionStringBuilder)
ICustomTypeDescriptor.GetEvents(Attribute[])

Returns the events for this instance of a component using the specified attribute array as a filter.

(Inherited from DbConnectionStringBuilder)
ICustomTypeDescriptor.GetProperties()

Returns the properties for this instance of a component.

(Inherited from DbConnectionStringBuilder)
ICustomTypeDescriptor.GetProperties(Attribute[])

Returns the properties for this instance of a component using the attribute array as a filter.

(Inherited from DbConnectionStringBuilder)
ICustomTypeDescriptor.GetPropertyOwner(PropertyDescriptor)

Returns an object that contains the property described by the specified property descriptor.

(Inherited from DbConnectionStringBuilder)
IDictionary.Add(Object, Object)

Adds an element with the provided key and value to the IDictionary object.

(Inherited from DbConnectionStringBuilder)
IDictionary.Contains(Object)

Determines whether the IDictionary object contains an element with the specified key.

(Inherited from DbConnectionStringBuilder)
IDictionary.GetEnumerator()

Returns an IDictionaryEnumerator object for the IDictionary object.

(Inherited from DbConnectionStringBuilder)
IDictionary.Item[Object]

Gets or sets the element with the specified key.

(Inherited from DbConnectionStringBuilder)
IDictionary.Remove(Object)

Removes the element with the specified key from the IDictionary object.

(Inherited from DbConnectionStringBuilder)
IEnumerable.GetEnumerator()

Returns an enumerator that iterates through a collection.

(Inherited from DbConnectionStringBuilder)

Extension Methods

Cast<TResult>(IEnumerable)

Casts the elements of an IEnumerable to the specified type.

OfType<TResult>(IEnumerable)

Filters the elements of an IEnumerable based on a specified type.

AsParallel(IEnumerable)

Enables parallelization of a query.

AsQueryable(IEnumerable)

Converts an IEnumerable to an IQueryable.

Applies to

See also