I have strongly typed entity class, which is used for Linq-To-Sql:
[Table(Name = "_Reference2")]
public class Customer
{
[Column(Name = "_IDRRef")]
public Binary Reference { get; set; }
[Column(Name = "_Fld196")]
public string Account { get; set; }
// and so on...
}
But it turned out, that we’ll have more databases with same type of entity (Customer), but table and column names are different, table structures may slightly differ also (in data types, e.g.).
Is there any way to dynamically map a call to this class accordingly to the database name? Can we change names of table and column dynamically? What is the best practices in such situations?
We wish to limit our changes of code to “data domain” project, and to leave web UI part of solution untouched.
P.S.: Databases are from third-party software, we haven’t any control of them (changes in structure are not allowed).
You can use mapping in XML and emit that XML on the fly. This of course has some limitations – structure and data types of your table must mostly match your entity. If they don’t you will also need a new class.