c# - Entity Framework DbContext dynamic instatiation with custom Connection String -


migrating objectcontext dbcontext code-generation, realized context class generated (which inherits dbcontext) has no constructor receives connectionstring neither entityconnection (like objectcontext child class had).

this problem in application since need instantiate context dinamically concrete type, using runtime generated connection string.

any ideas?

on class inherits dbcontext, should able specify base constructor takes connection sting:

public class mydbcontext : dbcontext {     public mydbcontext(string connstring)         : base(connstring)     {     } } 

you have use sqlconnection builder though:

sqlconnectionstringbuilder connbuilder= new sqlconnectionstringbuilder(dbconnstring); 

and use in constructor:

mydbcontext dbcontext = new mydbcontext(connbuilder.tostring()); 

Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

javascript - Clean way to programmatically use CSS transitions from JS? -

android - send complex objects as post php java -