3

クラスを自動生成する方法では、接続文字列をパラメーターとして取りませんが、生成されたコードは接続文字列を基本クラスに渡します。私は自分でテンプレートを編集できますが、モデルを再生成する可能性があり (おそらく削除して再作成することもできます)、テンプレートに影響を与えたくないので、より良い方法はありませんか?

//------------------------------------------------------------------------------
// <auto-generated>
//    This code was generated from a template.
//
//    Manual changes to this file may cause unexpected behavior in your application.
//    Manual changes to this file will be overwritten if the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------

public partial class MyEntities : DbContext
{
    public MyEntities()
        : base("<Connection string>")
    {
    }
...

私はDBファーストのアプローチを使用しています。すべて正常に動作しますが、データベースの正確なコピーを作成したので、2 つを切り替える必要があります。

4

1 に答える 1