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;
Source: stackoverflow.com
Related Articles
- Map class to tables with different table names but same column structure
- Linq Join 2 tables, the column names are different but the values in the column are the same in both tables
- Concat 2 tables with different structure using linq
- Inserting data into different tables at the same time with Linq-to-SQL
- C# LINQ - Select statement that compares all properties of a class with a different instance of the same class?
- Distinct rows from db table with unique IDs but same names
- LINQ Join with same Name on different tables
- Class with multiple List Properties of same type but with different restrictions
- LINQ Query over heterogeneous collection of different types with same base class
- how to copy one column data to another column with in the same table using linq?
- multiple joins in LINQ Query with 3 tables on the same column
- Linq Query multiples tables join with array of varying table names
- Generic code to determine how many rows from a table are in a different table with matching structure?
- How to manage multiple tables with the same structure
- Array containing same data from table instead of different data with ToArray()
- Linq Inner join for different column in same table
- Linq joining same table with 4 different foreign keys
- Map column names of sql table with an object property, C#, LINQ
- LINQ: Get Table Column Names
- How to remove an element from an xml using Xdocument when we have multiple elements with same name but different attributes
- C# re-use LINQ expression for different properties with same type
- LINQ method How to SelectMany with additional column from Parent class
- LINQ-to-Entities, Ambiguous Column Name with association between two views with the same column name
- Joining two tables with LINQ while also returning null records from the second table
- How do you query several tables at once given a list of table names as strings?
- LINQ Union between two tables with the same fields and then returned in a collection
- Filling a hierarchical class structure with data
- how to create a pivot table with dynamic column using linq tree expression
- Assign multiple tables to single class in linq table mapping
- Compare items in different dictionaries with same key using LINQ
- Having an issue with "DataReader already open"
- Linq orderby national character sets
- How to create optimal query?
- Powershell equivalent of ".Single()" For a C#/Java programmer
- Dynamic distinct values using Linq to SQL
- C# Use Linq to Extract a single XML attribute for each XML file in a directory
- retrieve all data in list instead of one specific item in list
- LINQ filter nullable datetime with matching params?
- Linq to XML to create 1 record per specific element
- How do I write an MVC Entity Framework select query from the controller using passed string arguments?
- List<> OrderBy IComparer?
- Why did my code work when I changed it from IEnumerable to List?
- How to write the right linq where clause?
- LINQ queries take more time to execute
- What is the big deal with IQueryable?
- Partial string matching with LINQ/C#
- Custom Nullable<T> Extension Methods and SelectMany
- Linq left outer join
- LINQ to XML Select Statement - No Results
- Setting properties of object