私は間違っていることを知らず、データベースプロジェクトをセットアップするのに非常に苦労し、connectionstring dbcontextに関連したエラーを続けます。ConnectionStrings EFコアのDbContext
私はちょうど
問題は私のデータが間違った場所にあると思われると、私はそれを修正するかどうかはわからないところで私の他のdbcontextあるlocaldbに接続している1 applicationdbcontextを持っています。このコードは、私のモデルフォルダ、私はこのコードを持っているstartup.csで
public DbSet<Customer> Customers { get; set; }
public DbSet<Job> Jobs { get; set; }
public DbSet<Order> Orders { get; set; }
public DbSet<Staff> Staff { get; set; }
public DbSet<RequestType> RequestType { get; set; }
public DbSet<CustomerJob> CustomerJobs { get; set; }
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.UseSqlServer("Server=(localdb)\\mssqllocaldb;Database=Customers;Trusted_Connection=True;");
}
... services.AddDbContext(=> options.UseSqlServer(Configuration.GetConnectionString( "DefaultConnectionを")のオプション))です。 services.AddDbContext(options => options.UseSqlServer(Configuration.GetConnectionString( "ProdConnection")));まだ私はこのコードを持っている私のAppSettings configに
..
"ConnectionStrings": {
"DefaultConnection": "Server=(localdb)\\mssqllocaldb;Database=BRSCRM;Trusted_Connection=True;MultipleActiveResultSets=true",
"ProdConnection": "Server=(localdb\\mssqllocaldb;Database=Customers;Trusted_Connection=True;MultipleActiveResults=true"
},
私は設定が供給されていること、エラーが使用されていない取得私のプロジェクト、実際に制御のDI反転、その袋を実行します猫とその火の上に!
エラーは次のようなものです.AddDbContextがコンフィグレーションで呼び出されましたが、コンテキストタイプ 'CustomerContext'はパラメータのないコンストラクタのみを宣言します。つまり、AddDbContextに渡された設定は決して使用されません。構成がAddDbContextに渡された場合、 'CustomerContext'はDbContextOptionsを受け入れるコンストラクタを宣言し、DbContextの基本コンストラクタにそのコンストラクタを渡す必要があるため、onConfiguringをオーバーライドする必要があります。 。 –
webdev8183
ugh明らかに、startup.csファイル内の文字列はまったく必要なく、onconfiguringからのオーバーライドがうまくいきましたが、それはばかげて同じ接続文字列を2回使用したかったのです。 – webdev8183