title: How to I define/change the mappings for Linq To Sql in code
body: <p>I wish to be able to change the table a class is mapped to at run time, I can’t do this if all the mappings are defined with attributes.  Therefore is there a way to define the mappings at runtime in code.</p>
  
  <p>(I would rather not have to maintain xml mapping files.)</p>
  
  <hr>
  
  <p>Say I have two tables:</p>
  
  <ul>
  <li>OldData</li>
  <li>NewData</li>
  </ul>
  
  <p>and sometimes I wished to query OldData and other times I wished to query NewData.   I want to use the same code to build the queries in both cases.</p>
  
  <hr>
  
  <p>See also "<a href="https://stackoverflow.com/questions/3428069/how-to-map-an-entity-framework-model-to-a-table-name-dynamically">How to map an Entity framework model to a table name dynamically</a>"</p>