I have to support 2 different schema versions of a database. The new version has 2 extra tables.
Is it possible to use same DBContext object but with 2 different mappings?
This is what I have:
Code: Select all
public class MyDataContext: DataContext
{
public Table<Table1> Table1;
public Table<Table2> Table2;
public MyDataContext(string connectionString, bool isNewSchema): base( connectionString, isNewSchema? MyMapping.NewMappingSource: MyMapping.LegacyMappingSource)
{
}
}
public static class MyMapping
{
public MappingSource NewMappingSource
{
get {
var mySqlDataProvider = new MySqlDataProvider();
var builder = new FluentMappingBuilder(mySqlDataProvider);
var entity1 = builder.Entity<Table1>;
// Do entity1 column mappings
var entity2 = builder.Entity<Table2>;
// do entity2 column mappings
}
}
public MappingSource LegacyMappingSource
{
get {
var mySqlDataProvider = new MySqlDataProvider();
var builder = new FluentMappingBuilder(mySqlDataProvider);
var entity1 = builder.Entity<Table1>;
// Do entity1 column mappings
builder.Ignore<Table2>;
}
}
}
"System.InvalidOperationException
Unable to resolve root for type Table2"
Anyway around this? I am trying to avoid creating a new DataContext. Appreciate the help.