Hi,
I have two tables namely Table1 ,Table2 and two schemas Sch1,Sch2 in my database and the tables present in both the schemas.
like this:
Sch1.Table1(T1Col1,T1Col2)
Sch1.Table2(T2Col1,T2Col2)
Sch2.Table1(T1Col1,T1Col2)
Sch2.Table2(T2Col1,T2Col2)
i have a UI page which contains, a drop down and three tabs.
From a UI page, user will select one schema from the drop down, then the data related to that schema should be loaded to a grid. user has an option to create a new schema with tables mentioned above. that means in future we may get lot of schemas each with the same table structure.
I need to design a data model, that handles all these. as the schema names can be changing, i need to create more dynamic kind of Entity Framework.
can anybody suggest best way to do it?
I did it in the Following way:
<pre>
Class myDataContext: DbContext
{
static string targetSchema=string.empty;
public myDataContext(string connectionString,string Schemaname):base(connectionString)
{
targetSchema=schemaName;
}
-----blah--blah
public override void OnModelCreation(ModelBuilder)
{
ModelBuilder.Entity<Table1>().ToTable("Table1",targetSchema);
ModelBuilder.Entity<Table2>().ToTable("Table2",targetSchema);
}
}
I'm not sure about the inherent evil in the code. Please suggest me if there is any better way to do it
Thanks in advance :)