使用相同的類(模型)創建兩個表

asp.net-core ef-migrations entity-framework-core

即時通訊使用SqlLite和.net核心。我怎樣才能重用同一個類(Model)來創建兩個表?

 public class Venda
    {
        public int ID { get; set; }
        public int MasterID { get; set; }
        public int UsuarioID { get; set; }
        public int Status { get; set; }
    }

/* **********************************************  */

  public class MyEntities : DbContext
    {
        public DbSet<Venda> VendasRecebidas { get; set; } //Table one
        public DbSet<Venda> VendasTemp { get; set; } //Table two

        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {
            optionsBuilder.UseSqlite("Filename=./mydb.db");
        }
    }

一般承認的答案

使用C#繼承

public class VendaRecebida
{
    public int ID { get; set; }
    public int MasterID { get; set; }
    public int UsuarioID { get; set; }
    public int Status { get; set; }
}

public class VendaTemp : VendaRecebida
{
}

/* **********************************************  */

public class MyEntities : DbContext
{
    public DbSet<VendaRecebida> VendasRecebida { get; set; } //Table one
    public DbSet<VendaTemp> VendasTemp { get; set; } //Table two


Related

許可下: CC-BY-SA with attribution
不隸屬於 Stack Overflow
許可下: CC-BY-SA with attribution
不隸屬於 Stack Overflow