score:2

Accepted answer

With EF Code First you can map the entity to different tables dynamically:

public class OrderContext : DbContext
{
    private readonly string _tableName;

    public OrderContext(string tableName)
        : base("name=OrderContext")
    {
        _tableName = tableName;
    }

    protected override void OnModelCreating(DbModelBuilder modelBuilder)
    {
        modelBuilder.Entity<Order>().ToTable(_tableName);

        base.OnModelCreating(modelBuilder);
    }

    public ICollection<Order> Orders { get; set; }
}

Usage:

var orders = new OrderContext("Orders").Orders;
var legacyOrders = new OrderContext("LegacyOrders").Orders;

Related Articles