public static void InsertCountryExchange(Country country, List <string> exchanges) { using (var context = new StockExchangeDbContext()) { context.Countries.Add(country); context.SaveChanges(); int countryId = country.CountryId; List <Exchange> newExchanges = new List <Exchange>(); foreach (var exchange in exchanges) { newExchanges.Add(new Exchange { Name = exchange, CountryId = countryId }); } context.Exchanges.AddRange(newExchanges); context.SaveChanges(); } }
public int SaveChanges() { return(StockExchangeDbContext.SaveChanges()); }