internal RepositoryImplementation(string connectionString) { DB = DBDataContext.NewInstance(connectionString); DataLoadOptions Load = new DataLoadOptions(); Load.LoadWith <User>(u => u.UserType); Load.LoadWith <Pet>(p => p.Owner); Load.LoadWith <Pet>(p => p.Specie); Load.LoadWith <Address>(a => a.Client); Load.LoadWith <Appointment>(a => a.Pet); Load.LoadWith <Appointment>(a => a.Address); Load.LoadWith <Appointment>(a => a.Doctor); Load.LoadWith <Appointment>(a => a.AppointmentType); DB.LoadOptions = Load; }
public static DBDataContext NewInstance(string connectionString) { //This one, gives access to the tables through properties if (connectionString.Contains("|DataDirectory|")) { connectionString = connectionString.Replace("|DataDirectory|", Environment.CurrentDirectory); } DBDataContext db = new DBDataContext(connectionString); if (!db.DatabaseExists()) { db.CreateDatabase(); db.Dispose(); //A second instance is required, so it reloads the tables that were recently created; db = new DBDataContext(connectionString); //Seeding the database with the basic user types db.UserTypes.InsertOnSubmit(new UserType() { Name = "Admin" }); db.UserTypes.InsertOnSubmit(new UserType() { Name = "Staff" }); //Seeding the table specie db.Species.InsertOnSubmit(new Specie() { Name = "Dog" }); db.Species.InsertOnSubmit(new Specie() { Name = "Cat" }); db.Species.InsertOnSubmit(new Specie() { Name = "Fish" }); db.Species.InsertOnSubmit(new Specie() { Name = "Horse" }); db.SubmitChanges(); db.Users.InsertOnSubmit(new User() { Name = "Admin", Password = "******", Username = "******", UserType = db.UserTypes.FirstOrDefault() }); db.SubmitChanges(); db.Addresses.InsertOnSubmit(new Address() { Line1 = "Clinic - 100 Fairway", Apartment = "23", City = "Kitchener", Province = Province.ON, PostalCode = "N2C 1X4" }); db.AppointmentTypes.InsertOnSubmit(new AppointmentType() { Name = "Vaccine" }); db.AppointmentTypes.InsertOnSubmit(new AppointmentType() { Name = "Surgery" }); db.AppointmentTypes.InsertOnSubmit(new AppointmentType() { Name = "Therapeutic" }); db.SubmitChanges(); db.Dispose(); return(new DBDataContext(connectionString)); } return(db); }