static void AddBook() { using (var context = new BookContext()) { Console.WriteLine("Enter book title, please: "); var title = Console.ReadLine(); Console.WriteLine("Enter author name: "); var authorNames = Console.ReadLine(); string firstName, midName = string.Empty, lastName; var names = authorNames.Split(' '); if (names.Length > 2) { firstName = names[0]; midName = names[1]; lastName = names[2]; } else { firstName = names[0]; lastName = names[2]; } var existingAuthor = context.FindAuthorByName(firstName, midName, lastName).FirstOrDefault(); context.Add(new Book() { BookId = Guid.NewGuid(), Title = title, Author = existingAuthor ?? new Author() { FirstName = firstName, MiddleName = midName, LastName = lastName } }); } }