I have one ASP-WebForms-Application for 3 Companies. Every Company has its own Database and own EDMX-Model. The Structure in the Databases is the same. On Parameters I am checking which Company it is and want to have one DbContext for all the Models.
I am very new in Entity Framework and don't know how to make one Context for a few Models.
I have tried to make a class that gives me a DbContext, in which I want to make the DBContext one of the Models.
I am trying:
public static DbContext holeDbContextWsvWsbSvs()
{
DbContext context = new DbContext();
string verbandKürzel = config.holeVerbandKürzel();
if (verbandKürzel == "wsv")
{
context = new wsvEntities();
}
else if (verbandKürzel == "wsb")
{
context = new wsbEntities();
}
else if (verbandKürzel == "svs")
{
context = new svsEntities();
}
return context;
}
But in Entity Framework 6.0 it seems as an emtpy Constructor is not possible!
Is it possible to intialize a Null(Fake,Pseudo)-DbContext or something and then change it to the Model-Context?
Can anyone give me an impulse please, how can i realize my plans?
EDIT: Okay, changing the Context to the Model inside the Method achieved by giving the Constructor any string. But although giving the Context a specific Model inside the method, I am returning a DbContext an can not use Object-Attributes after that.
Any Suggestions? Or do really have to make at every position i need to work with the DataModel IF-ELSEs and do the same logic for each Model?