private Author CreateOrLoadAuthor(BookstoreEntities context, string authorName) { Author author = context.Authors.FirstOrDefault<Author>(a => a.Name == authorName); if (author != null) { return author; } Author newAuthor = new Author() { Name = authorName }; context.Authors.Add(newAuthor); context.SaveChanges(); return newAuthor; }