Using the same class (model) to create two tables

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

Question

im using SqlLite and .net core. How can i reuse the same class (Model) to create two table?

 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
1
12/22/2016 8:47:55 PM

Accepted Answer

Using C# inheritance

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
2
12/23/2016 12:50:54 AM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow