Click here to Skip to main content
15,887,984 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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:
C#
<pre>
Class myDataContext: DbContext
{
     static string targetSchema=string.empty;
     /*Constructor*/
     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 :)
Posted
Updated 8-Aug-14 2:50am

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900