Code-First ASP.Net Core 2.0プロジェクトで、Entity Framework Core 2.0を使用してプログラムで移行を適用しようとしています。端末を介して手動で移行を実行すると、問題なく適用されます。私のStartup
クラスにマイグレーションを適用すると、データベースモデルが変わることはありません。移行が適用されていません
これは間違っていますか?
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
public IConfiguration Configuration { get; }
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc();
services.AddEntityFrameworkSqlite();
services.AddDbContext<ApplicationContext>(options => options.UseSqlite("Data Source=blogging.db"));
services.AddDbContext<UserContext>(options => options.UseSqlite("Data Source=blogging.db"));
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
app.UseMvc();
var services = app.ApplicationServices.GetService<IServiceScopeFactory>();
var context = services.CreateScope().ServiceProvider.GetRequiredService<ApplicationContext>();
context.Database.Migrate();
}
私は、端末からこれを実行することができ、それが正常に動作します:
DOTNETのEFの移行は、私は複数の
DataContext
タイプを持っているFourthMigration --context EFCore_Test.DataAccess.ApplicationContext
を追加します。 1つだけがデータモデル全体を表し、残りは、より多くのドメイン特有のマナーでデータベースにアクセスするために使用されます。 ApplicationContext
は、私の「すべての台所シンク」データコンテキストを表しています。このコンテキストでは、移行と更新を実行します。
Azureにデプロイする準備として、私は、Webベースのツールをコマンドラインで実行するためにpowershellスクリプトをワイヤリングする代わりに、それぞれの展開でweb-appを移行させたいと思っています。