Ben Junior
Ben Junior

Reputation: 2589

Is it possible to map 2 tables to one single model using EF 6?

The model Customer is mapped to Customers table. Is it possible to also map to another table named OldCustomers using the same model? There is no relation key between the tables and not looking for data normalization. Just need this other exactly model/table structure. In case this is not supported, what would be the best option?

Upvotes: 0

Views: 108

Answers (1)

Sid
Sid

Reputation: 14916

override protected override void OnModelCreating(DbModelBuilder modelBuilder) in the class which inherits from DbContext and then you can do the following:

protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
    base.OnModelCreating(modelBuilder);

    modelBuilder.Entity<MyCoolModel>().ToTable("MyTab1");
    modelBuilder.Entity<MyCoolModel>().ToTable("MyTab2");

}

Upvotes: 1

Related Questions