using System.Collections.Generic;
using Microsoft.EntityFrameworkCore;
namespace EfExtensionsTest
static void Main(string[] args)
using (var context = new BookStore())
var authors = new List<Author>
BirthDate = DateTime.Parse("1985-09-01"),
new Book { Title = "Introduction to Machine Learning"},
new Book { Title = "Advanced Topics on Machine Learning"},
new Book { Title = "Introduction to Computing"}
BirthDate = DateTime.Parse("1970-09-01"),
new Book { Title = "Introduction to Microeconomics"}
BirthDate = DateTime.Parse("1963-09-01"),
new Book { Title = "Calculus I"},
new Book { Title = "Calculus II"}
context.BulkInsert(authors, options => options.IncludeGraph = true);
using (var context = new BookStore())
var list = context.Authors
foreach (var author in list)
Console.WriteLine(author.FirstName + " " + author.LastName);
foreach (var book in author.Books)
Console.WriteLine("\t" + book.Title);
public int AuthorId { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public DateTime BirthDate { get; set; }
public List<Book> Books { get; set; }
public int BookId { get; set; }
public string Title { get; set; }
public Author Author { get; set; }
public class BookStore : DbContext
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
optionsBuilder.UseInMemoryDatabase(databaseName: "BookStoreDb");
public DbSet<Author> Authors { get; set; }
public DbSet<Book> Books { get; set; }