I am using the Repository pattern for EF and have ran into a problem in that I cannot figure out how to set the connection string for the DbContext through a variable. Currently my constructor is parameterless (it has to be to fit with he pattern) i.e.
IUnitOfWork uow = new UnitOfWork<EMDataContext>();
DeviceService deviceService = new DeviceService(uow);
var what = deviceService.GetAllDevices();
public UnitOfWork()
{
_ctx = new TContext();
_repositories = new Dictionary<Type, object>();
_disposed = false;
}
EMDataContext used to take a string in its constructor to define the ConnectionString but can no longer do that so how do I actually tell the EMDataContext what to connect to when its created in this fashion?
new UnitOfWork<EMDataContext>();?TContext? does it inherit something that allows you to set a connctionstring? Also - a .config file is a good place for the connectionstring. EF will look for it there if you don't directly specify where it is.