Hi Dharmender,
Below code works for me
I have created parameterized DBcontext with Dbconnectionstring Parameter, in this way we can pass connection string before binding Customer Data.
DBcontext class for customer
public class CustomerDbContext: DbContext
{
public CustomerDbContext(string databaseConnection)
: base()
{
ConnectionString = databaseConnection.ToString();
}
public string ConnectionString { get; set; }
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.UseLazyLoadingProxies(true).UseSqlServer(ConnectionString);
}
public DbSet<Customer> Customer { get; set; }
get Method in Repository class
private CustomerDbContext _contextFactory;
public List<Customer> GetCustomer(string databaseName)
{
_contextFactory = new CustomerDbContext(databaseName); //first set the connection string
return _contextFactory.Customer.Select(p => this.mapper.Map<CustomerResponse>(p)).ToList(); //Bind data from provided server
}