private static List <Unit> GenerateAndAddCompanies(int numberOfCompanies, PersonalLegacyContext context) { var companies = UnitFactory.GetCompanyFactory(_regionIdHardcoded) .Generate(numberOfCompanies); context.Units.AddRange(companies); context.SaveChanges(); var unitContentBooks = companies.SelectMany(c => new List <UnitContentBook> { new UnitContentBook { UnitId = c.Id, ContentBookId = 1 }, new UnitContentBook { UnitId = c.Id, ContentBookId = 2 }, new UnitContentBook { UnitId = c.Id, ContentBookId = 8 }, }); context.UnitContentBooks.AddRange(unitContentBooks); context.SaveChanges(); return(companies); }