2017-07-31 20 views
0

私は複数のasp netコアクラスライブラリを作成しました。また、各ライブラリには1つのDBコンテキストが含まれています。私のプロジェクトごとに、私は1つのデータベースにすべてのdbcontexts(サブスクリプション、テナント、従業員dbコンテキストなど)をポイントしています。複数のdbcontextを持つ1つのデータベースを指す方法

これは、私は以下のように私のホームコントローラでそれらを利用しています私のstartup.cs

services.AddDbContext<ApplicationDbContext>(options => 
      options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection"))); 
     services.AddDbContext<Employees.EmployeeDbContext>(options => 
      options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection"))); 
     services.AddDbContext<Tenants.TenantDbContext>(options => 
      options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection"))); 

です。

EmployeeManager EmployeeManager; 
    TenantManager TenantManager; 
    public HomeController(EmployeeDbContext Context,TenantDbContext tenant) 
    { 
     EmployeeManager = new EmployeeManager(new EmployeeRepository(Context)); 
     TenantManager = new TenantManager(new TenantRepository(tenant)); 
    } 

とその作成のみ従業員テーブルが、私はtenants..etc必要も、同じデータベース

に私はここに打たれてしまったことを行う方法はあります。誰でも私を助けることができます。

+0

アプリケーションが複数のDbContextsを必要としないのはなぜ?私は、単一のデータベースでより多くのコンテキストを使用することはできません。これはおそらく、使用するよりも多くの問題を引き起こすでしょう:) –

+0

私たちはそれらのコアライブラリを複数のプロジェクトで使いたいと思いますので、 –

答えて

0

私はあなたがテーブルを作成するコンテキストをポイントする必要があると思う:

DOTNETのCLIコマンドを:

dotnet ef migrations add -c TenantDbContext InitialDatabase 

dotnet ef database update -c TenantDbContext 
関連する問題