1

私のWebサイトには、次のような通常のADO.NET接続文字列があります。

現在、Entity Frameworkは、独自の接続文字列を同じデータベースに追加しました。

実行時に1つのADO.NET接続文字列のみを使用してエンティティ接続文字列を作成するにはどうすればよいですか?

4

1 に答える 1

3

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";
using (EntityConnection conn =
    new EntityConnection(entityBuilder.ToString()))
{
    conn.Open();
    Console.WriteLine("Just testing the connection.");
    conn.Close();
}
于 2012-12-02T23:08:15.193 に答える