使用相同的类(模型)创建两个表

时间:2016-12-22 18:46:32

标签: asp.net-core entity-framework-core ef-migrations

我正在使用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");
        }
    }

1 个答案:

答案 0 :(得分:2)

使用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