Skip to content

Instantly share code, notes, and snippets.


explorer14/Persistence.cs Secret

Created Dec 22, 2019
What would you like to do?
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'");
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
You can’t perform that action at this time.