using Microsoft.EntityFrameworkCore;
using System.ComponentModel.DataAnnotations.Schema;
using System.Collections.Generic;
static void Main(string[] args)
var options = new DbContextOptionsBuilder<BloggingContext>()
.UseInMemoryDatabase(databaseName: "blarg123")
using (var context = new BloggingContext(options))
var blog = new Blog { Id = 1, Url = "http://sample.com" };
var post = new Post { Id = 1, BlogId = 1 };
using (var context = new BloggingContext(options))
var post = context.Set<Post>().AsNoTracking().First();
context.Entry(post).Reference(x => x.Blog).Load();
Console.WriteLine(post.Blog.Url);
Console.WriteLine(context.Set<Post>().Local.Count());
Console.WriteLine(context.Set<Blog>().Local.Count());
public class BloggingContext : DbContext
public BloggingContext(){ }
public BloggingContext(DbContextOptions<BloggingContext> options)
protected override void OnModelCreating(ModelBuilder modelBuilder)
modelBuilder.Entity<Blog>();
modelBuilder.Entity<Post>()
.HasForeignKey(x => x.BlogId);
public int Id { get; set; }
public string Url { get; set; }
public int Id { get; set; }
public string Notes { get; set; }
public Blog Blog { get; set; }
public int BlogId { get; set; }