Skip to content

Instantly share code, notes, and snippets.

@explorer14
Created December 22, 2019 22:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save explorer14/a522fa4437bd6289458b5e923677af09 to your computer and use it in GitHub Desktop.
Save explorer14/a522fa4437bd6289458b5e923677af09 to your computer and use it in GitHub Desktop.
private static void Main(string[] args)
{
DbContextOptionsBuilder<MyContext> builder = new DbContextOptionsBuilder<MyContext>();
builder.UseSqlServer("<connection string>");
Guid blogId;
Guid postIdToRemove;
// Let's create the Aggregate root first i.e. Blog
using(var ctx = new MyContext(builder.Options))
{
var blog = new Blog("Aman'sThoughts.com");
ctx.Blogs.Add(blog);
ctx.SaveChanges();
blogId = blog.Id;
}
// Now let's publish some posts in the blog
using (var ctx = new MyContext(builder.Options))
{
var blog = ctx.Blogs.Where(x => x.Id == blogId).Include(x => x.Posts).FirstOrDefault();
blog.CreatePost("Migrating from EF Core 2. to EF Core 3.0", "Its a bit broken!");
blog.CreatePost("Migrating from .NET Core 2.2 to NET Core 3.1", "Went kinda ok!");
ctx.SaveChanges(); // <--- this is where it blows up!
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment