Entity Framework が SQL データベースに接続する方法を「手動で」管理できるようにしたいと考えています。
私が念頭に置いているのは、データベースに接続する関数をオーバーライドするようなものです。
public override SqlConnection getNewConnection()
{
// return the connection to be used
}
これは可能ですか?
更新:受け取った回答に基づいて書いたものは次のとおりです。
System.Data.EntityClient.EntityConnection connection = new System.Data.EntityClient.EntityConnection("metadata=res://*/Models.ADLEntities.csdl|res://*/Models.ADLEntities.ssdl|res://*/Models.ADLEntities.msl;provider=System.Data.SqlClient;provider connection string="data source=myserver;initial catalog=mycatalog;integrated security=True;multipleactiveresultsets=True;App=EntityFramework"");
entities = new Models.ModswebEntities(connection);
EDMX オブジェクトを生成した VS ウィザードによって生成された web.config から接続文字列をコピーして、このコードを作成しました。ただし、このコードを実行すると、というエラーが表示されますKeyword not supported: 'data source'
。どうすればこれを修正できますか?