我们最近在.NET Core中创建了一个Web项目,并通过NPGSQL Entity Framework扩展使用PostgreSQL。起初,根本没有问题。但是在尝试添加更多模式时,未创建新模式。根据互联网上的其他帖子,我们不应局限于任何数量的模式。有人知道可能导致问题的原因吗?
P.S。:删除原始架构后,成功创建了新架构。但是,尝试添加下一个模式而不删除前一个模式似乎是一个问题。
FooDbContext.cs
public class FooDbContext : DbContext
{
/// <summary>
/// For unit testing.
/// </summary>
public FooDbContext()
: base()
{
}
public FooDbContext(DbContextOptions<FooDbContext> options)
: base(options)
{
}
public virtual DbSet<Person> People { get; set; }
public virtual DbSet<Project> Projects { get; set; }
public virtual DbSet<PersonOnProject> PeopleOnProjects { get; set; }
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.HasDefaultSchema("TestingFoo");
base.OnModelCreating(modelBuilder);
}
}
Startup.cs
...
public void ConfigureServices(IServiceCollection services)
{
// Add framework services.
services.AddEntityFrameworkNpgsql().AddDbContext<Model.FooDbContext>((provider, builder) => {
builder.UseNpgsql(Configuration.GetConnectionString("LocalDb"), b => b.MigrationsAssembly("TestingFoo"));
});
services.AddMvc();
}
....
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
loggerFactory.AddConsole(Configuration.GetSection("Logging"));
loggerFactory.AddDebug();
app.ApplicationServices.GetService<Model.FooDbContext>().Database.EnsureCreated();
app.Use(async (context, next) =>
{
await next();
if (context.Response.StatusCode == 404
&& !Path.HasExtension(context.Request.Path.Value))
{
context.Request.Path = "/index.html";
await next();
}
});
app.UseStaticFiles();
app.UseMvc();
}