Entity Framework throws exception - Invalid object name 'dbo.BaseCs'

后端 未结 12 945
挽巷
挽巷 2020-11-30 11:59

I\'ve followed Adam\'s answer here and the Entity Framework now works and the Seed() method also works.

But when I try to access the database l

12条回答
  •  情书的邮戳
    2020-11-30 12:44

    You have to define both the schema and the table in two different places.

    the context defines the schema

    public class BContext : DbContext
    {
        public BContext(DbContextOptions options) : base(options)
        {
        }
    
        public DbSet PriorityOverrides { get; set; }
    
        protected override void OnModelCreating(ModelBuilder builder)
        {
            builder.HasDefaultSchema("My.Schema");
    
            builder.ApplyConfiguration(new OverrideConfiguration());
        }
    }
    

    and for each table

    class PriorityOverrideConfiguration : IEntityTypeConfiguration
    {
        public void Configure(EntityTypeBuilder builder)
        {
            builder.ToTable("PriorityOverrides");
            ...
        }
    }
    

提交回复
热议问题