private static IDictionary<string, int> PrefillAuthors(IList<boeken> books, AuthorRepository authorsRepo, UnitOfWork unitOfWork) { var allAuthorsInOldDb = books.Select(_ => _.auteurs.Trim()).Distinct().ToList(); var newAuthors = authorsRepo.All.ToList(); var result = new Dictionary<string, int>(); Console.WriteLine("Found {0} authors in old db", allAuthorsInOldDb.Count()); foreach(var a in allAuthorsInOldDb) { var candidate = newAuthors.FirstOrDefault(_ => _.Name.ToLower() == a.ToLower()); if (candidate == null) { candidate = new Author() { State = State.Added, Name = a }; authorsRepo.InsertOrUpdate(candidate); unitOfWork.Save(); newAuthors.Add(candidate); } result[a.ToLower()] = candidate.Id; } return result; }