EF7 Migrations - The corresponding CLR type for entity type '' is not instantiable
Please see: https://docs.microsoft.com/en-us/ef/core/modeling/inheritance
If you don’t want to expose a DbSet for one or more entities in the hierarchy, you can use the Fluent API to ensure they are included in the model.
If you don't want to have to create a DbSet
for each subclass then you have to explicitly define them in the OnModelCreating
override of the DbContext
:
public class CoreDbContext : IdentityDbContext<ApplicationUser>
{
public DbSet<Organization> Organization { get; set; }
public CoreDbContext(DbContextOptions<CoreDbContext> options)
: base(options)
{
}
protected override void OnModelCreating(ModelBuilder builder)
{
builder.Entity<Individual>();
builder.Entity<Company>();
base.OnModelCreating(builder);
// Customize the ASP.NET Identity model and override the defaults if needed.
// For example, you can rename the ASP.NET Identity table names and more.
// Add your customizations after calling base.OnModelCreating(builder);
}
}
Similar to the tutorial you linked, your DbSet<>
properties should be the inheriting Individual
and Company
classes.
Try having your CoreDbContext
look more like this:
public class CoreDbContext : IdentityDbContext<ApplicationUser>
{
public DbSet<Company> Companies { get; set; }
public DbSet<Individual> Individuals { get; set; }
public CoreDbContext(DbContextOptions<CoreDbContext> options)
: base(options)
{
}
protected override void OnModelCreating(ModelBuilder builder)
{
base.OnModelCreating(builder);
// Customize the ASP.NET Identity model and override the defaults if needed.
// For example, you can rename the ASP.NET Identity table names and more.
// Add your customizations after calling base.OnModelCreating(builder);
}
}