public static void DefineNewStudyCentres(IEnumerable <StudySiteItemModel> newStudyCentres) { using (var t = new TrialDataContext()) { if (t.StudyCentres.Any()) { throw new InvalidOperationException("Study Centres cannot be modified after creation"); } foreach (StudySiteItemModel s in newStudyCentres) { t.StudyCentres.Add(ViewModel.StudySitesViewModel.MapToStudySite(s)); } t.SaveChanges(true); } }
static void UpdateVA(string source, string dest) { List <VaccineAdministered> sourceVas; using (var db = new TrialDataContext(source)) { sourceVas = db.VaccinesAdministered.AsNoTracking().ToList(); } using (var db = new TrialDataContext(dest)) { var destVas = db.VaccinesAdministered.ToList(); int i = 0; while (sourceVas.Count > i && destVas.Count > i && sourceVas[i].Id == destVas[i].Id) { destVas[i].ParticipantId = sourceVas[i].ParticipantId; i++; } db.SaveChanges(); } }