private static int SaveOrganisationsToDb(OrganisationsInput organisations, CategoriesInput categories) { var changes = 0; using (var context = new CdcsContext()) { context.Database.EnsureDeleted(); context.Database.EnsureCreated(); context.Organisations.AddRange(organisations.Organisations); context.Accreditors.AddRange(organisations.Accreditors); context.Accreditations.AddRange(organisations.Accreditations); context.ContactModes.AddRange(organisations.ContactModes); context.GeographicalZones.AddRange(organisations.GeographicalZones); context.OrganisationLanguages.AddRange(organisations.OrganisationLanguages); context.OrganisationLegalStatuses.AddRange(organisations.OrganisationLegalStatuses); context.Languages.AddRange(organisations.Languages); context.Sectors.AddRange(categories.Sectors); context.Topics.AddRange(categories.Topics); context.Categories.AddRange(categories.Categories); context.SectorCategoriesHierarchies.AddRange(categories.SectorCategoriesHierarchies); changes = context.SaveChanges(); } return(changes); }
private static int SaveToDb(IReadOnlyCollection <ICdcsIdentity> cdcs_objects) { var types = cdcs_objects.Select(o => o.GetType()).Distinct(); var nb_of_changes = 0; using (var context = new CdcsContext()) { context.Database.EnsureDeleted(); context.Database.EnsureCreated(); // context.Database.Migrate(); foreach (var t in types) { switch (t.Name) { case "CdcsActionZone": context.CdcsActionZones.AddRange(GetCdcsObjectByType <CdcsActionZone>(cdcs_objects)); break; case "CdcsAccreditationType": context.CdcsAccreditationTypes.AddRange(GetCdcsObjectByType <CdcsAccreditationType>(cdcs_objects)); break; case "CdcsAccreditor": context.CdcsAccreditors.AddRange(GetCdcsObjectByType <CdcsAccreditor>(cdcs_objects)); break; case "CdcsLanguage": context.CdcsLanguages.AddRange(GetCdcsObjectByType <CdcsLanguage>(cdcs_objects)); break; case "CdcsLegalStatus": context.CdcsLegalStatuses.AddRange(GetCdcsObjectByType <CdcsLegalStatus>(cdcs_objects)); break; case "CdcsSector": context.CdcsSectors.AddRange(GetCdcsObjectByType <CdcsSector>(cdcs_objects)); break; case "CdcsServiceType": context.CdcsServiceTypes.AddRange(GetCdcsObjectByType <CdcsServiceType>(cdcs_objects)); break; } } nb_of_changes = context.SaveChanges(); } return(nb_of_changes); }
public int SaveChanges() { return(_db.SaveChanges()); }