At the minute I am creating my entities using unit of work principle that their is only one context per request.
But I now have a request that I must be able to change the database on the fly at runtime this would be done on the loading of application and they have allowed us to reload the application.
public void AddToAppointment(Appointment newAppointment)
{
using (var myContext = new SMBASchedulerEntities())
{
myContext.Appointments.Add(newAppointment);
myContext.SaveChanges();
}
}
The above code is in my SourceContext
class and looking for some guidance on this.
My main question is thus can I change the SMBASchedulerEntities
to get its connection information from a class if so what would this class look like and function as. The databases will all have the same schema.
What is the best practise for this method?
Edit 2
Sorry I should have stated my context class is like this
public class SourceContext : ContextBase
{
// public SMBASchedulerEntities _sourceEntities = new SMBASchedulerEntities();
// private SystemDa _systemDB = new SystemDa();
then my other methods
}
Which context class should I pass the connection to and how would I build that?
Edit 3
This is showing my main entity class which is autogenerated.
using System;
using System.Data.Entity;
using System.Data.Entity.Infrastructure;
using System.Data.Entity.Core.Objects;
using System.Linq;
public partial class SMBASchedulerEntities : DbContext
{
public SMBASchedulerEntities()
: base("name=SMBASchedulerEntities")
{
}
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
throw new UnintentionalCodeFirstException();
}
}