0

We have an application that uses multiple databases for different users. We are using a generic repository and unit-of-work pattern and dependency injection. We have a DbContext which is a parameterized one. What we want is when users comes to our website, we want the DbContext point to their website for that particular transaction.

We tried registering the DbContext on the unity configuration and override it in the controller level. But that failed. Can anyone let us know how to get it done?

DBContext

public class TimperContext: IdentityDbContext<MyUser> 
{ 
    public TimperContext(string connectionString) : base(connectionString) { } 
    public DbSet<UserAddress> UserAddresses { get; set; }
}
Jamie Rees
  • 7,973
  • 2
  • 45
  • 83
Swagat Swain
  • 495
  • 1
  • 4
  • 22
  • 1
    Can you show your DBContext class? – Jamie Rees Nov 05 '15 at 14:07
  • `public class TimperContext: IdentityDbContext { public TimperContext(string connectionString) : base(connectionString) { } public DbSet UserAddresses { get; set; } }` – Swagat Swain Nov 05 '15 at 18:22
  • Your question is quite vague and difficult to answer because we know very little information on how your system interacts with your DB. Since you are passing in the `Connection String` why can't you just use a different connectionstring for a particular transaction? – Jamie Rees Nov 06 '15 at 08:54
  • Hi, you question did not contain much info. By right this way should work; just need to make sure the connectionString format is correct. https://msdn.microsoft.com/en-us/library/gg679467(v=vs.113).aspx This may be what you want. http://stackoverflow.com/questions/21165364/ef6-dbcontext-dynamic-connection-string – Lavande Nov 08 '15 at 13:12

0 Answers0