c# - How to configure DB connection at run time with EF 4.1 Code First -


i'm trying use ef 4.1 code first poco objects against legacy database. have many similar databases same schema, , need decide 1 connect @ runtime.

all examples i've seen show put connection string in app.config or web.config. won't work me since need dynamic behaviour.

what object/properties can manipulate control db settings dbcontext?

dbcontext has constructor accepts dbconnection instance, can spin using appropriate factory class.

i sort of thing in 1 of apps:

_context = new mydbcontext(     new sqlconnectionfactory(properties.settings.default.myconnectionstring)         .createconnection("databasename")); 

so can read connection string @ runtime , pass sqlconnectionfactory class, give me new connection using that.

i'm not sure "databasename" parameter used in case, since it's in connection string anyway. sure, i've made sure they're same.


Comments

Popular posts from this blog

c# - How to set Z index when using WPF DrawingContext? -

razor - Is this a bug in WebMatrix PageData? -

visual c++ - Using relative values in array sorting ( asm ) -