using System.Collections.Generic;
using Microsoft.EntityFrameworkCore;
public class BloggingContext : DbContext
public DbSet<Blog> Blogs { get; set; }
public DbSet<Post> Posts { get; set; }
public string DbPath { get; }
var folder = Environment.SpecialFolder.LocalApplicationData;
var path = Environment.GetFolderPath(folder);
protected override void OnConfiguring(DbContextOptionsBuilder options)
=> options.UseSqlite($"Data Source={DbPath}", x => x.UseNetTopologySuite());
public int BlogId { get; set; }
public string Url { get; set; }
public List<Post> Posts { get; } = new();
public int PostId { get; set; }
public string Title { get; set; }
public string Content { get; set; }
public int BlogId { get; set; }
public Blog Blog { get; set; }
public static void Main()
using var db = new BloggingContext();
db.Database.OpenConnection();
db.Database.EnsureCreated();
Console.WriteLine($"Database path: {db.DbPath}.");
Console.WriteLine("Inserting a new blog");
db.Add(new Blog { Url = "http://blogs.msdn.com/adonet" });
Console.WriteLine("Querying for a blog");
Console.WriteLine("Updating the blog and adding a post");
blog.Url = "https://devblogs.microsoft.com/dotnet";
new Post { Title = "Hello World", Content = "I wrote an app using EF Core!" });
Console.WriteLine("Delete the blog");