Il codice seguente genera solo una tabella "CertificateEvent".
Come posso ottenere l'eredità TPT in EF Core 2.0?
public abstract class CertificateEvent {
public int CertificateEventId { get; set; }
}
public class Assignment : CertificateEvent {...}
public class Assessment : CertificateEvent {...}
public class MyDbContext : DbContext
{
public MyDbContext(DbContextOptions<MyDbContext> options) : base(options)
{
}
public DbSet<Assessment> AssessorAssessments { get; set; }
public DbSet<Assignment> AssessorAssignments { get; set; }
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
modelBuilder.Entity<CertificateEvent>().ToTable(nameof(CertificateEvent));
modelBuilder.Entity<Assessment>().ToTable(nameof(Assessment));
modelBuilder.Entity<Assignment>().ToTable(nameof(Assignment));
}
}
class MyDesignTimeDbContextFactory : IDesignTimeDbContextFactory<MyDbContext>
{
public MyDbContext CreateDbContext(string[] args)
{
var builder = new DbContextOptionsBuilder<MyDbContext>();
builder.UseSqlServer("Server=(local);Database=Test;Trusted_Connection=True;MultipleActiveResultSets=true");
return new MyDbContext(builder.Options);
}
}
Ho anche provato le dotnet ef migrations add Inheritance
, ma non ha creato l'ereditarietà TPT nel database
TPT non è ancora in EF Core (ancora). Vedere
Il sentimento del nostro team è che TPT è generalmente un anti-modello e si traduce in problemi di prestazioni significativi in seguito. Sebbene abilitarlo, potrebbe far sì che alcune persone "più felici" inizino con questo, in ultima analisi, porta solo a dei problemi. Tuttavia, siamo disposti a prenderlo in considerazione, quindi lo lasciamo aperto e lo considereremo in base al feedback che otteniamo.