@rowanmiller can you help-me ?
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 onde
public DbSet<Venda> VendasTemp { get; set; } //Table two
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.UseSqlite("Filename=./mydb.db");
}
}
@LucasArgate EF Core only supports having one mapping in the model for each entity type. I.e. there aren't any supported cases in which two instance of the same type could end up being stored in different tables or different columns.
If you want something like this there are a couple of alternatives you can try. The most appropriate one is going to depend on your scenario:
Having two DbSets of two different types. The two types can inherit from (and even have all their properties defined in) a common base type as long as that base type isn't mapped in the EF Core model.
Having two separate derived DbContext
types which map the Venda
type to different tables.
Most helpful comment
@LucasArgate EF Core only supports having one mapping in the model for each entity type. I.e. there aren't any supported cases in which two instance of the same type could end up being stored in different tables or different columns.
If you want something like this there are a couple of alternatives you can try. The most appropriate one is going to depend on your scenario:
Having two DbSets of two different types. The two types can inherit from (and even have all their properties defined in) a common base type as long as that base type isn't mapped in the EF Core model.
Having two separate derived
DbContext
types which map theVenda
type to different tables.