我有两张名为“Tickets”和“Toys”的表。这些是2个不同的表格,数据。
[Table("Toy")]
public class Toy
{
public int ToyId{ get; set; }
public string Name{ get; set; }
public string Size{ get; set; }
}
[Table("Ticket")]
public class Ticket
{
public int TicketId{ get; set; }
public int Type{ get; set; }
public int Amount{ get; set; }
public DateTime Date{ get; set; }
}
public class InheritanceMappingContext : DbContext
{
public DbSet<Toy> Toys { get; set; }
public DbSet<Ticket> Tickets { get; set; }
}
但是现在我决定实现TPT继承,这样我将有一个名为“Product”宽度的表和一个“Id”列,它将是标识。现在2个类,“Ticket”和“Toys”应该继承自“Product”。但是在尝试更新数据库时遇到了很多错误。
public abstract class Product
{
public int Id{ get; set; }
public long Price{ get; set; }
}
[Table("Toys")]
public class Toys: Product
{
public string Name{ get; set; }
public string Size{ get; set; }
}
[Table("Ticket")]
public class Ticket: Product
{
public int Type{ get; set; }
public int Amount{ get; set; }
public DateTime Date{ get; set; }
}
public class InheritanceMappingContext : DbContext
{
public DbSet<Product> Products { get; set; }
}
理论上我知道,我应该: