diff --git "a/\344\272\202\344\270\203\345\205\253\347\263\237/\344\272\202\344\270\203\345\205\253\347\263\237.DataAccessLayer/BloggingContext.cs" "b/\344\272\202\344\270\203\345\205\253\347\263\237/\344\272\202\344\270\203\345\205\253\347\263\237.DataAccessLayer/BloggingContext.cs" index 0499248..e095419 100644 --- "a/\344\272\202\344\270\203\345\205\253\347\263\237/\344\272\202\344\270\203\345\205\253\347\263\237.DataAccessLayer/BloggingContext.cs" +++ "b/\344\272\202\344\270\203\345\205\253\347\263\237/\344\272\202\344\270\203\345\205\253\347\263\237.DataAccessLayer/BloggingContext.cs" @@ -10,8 +10,8 @@ public class BloggingContext : DbContext //public static readonly BloggingContext Default = new BloggingContext(); //public required DbSet Blogs { get; set; } //public required DbSet? Posts { get; set; } - public DbSet? Blogs { get; set; } - public DbSet? Posts { get; set; } + public DbSet Blogs { get; set; } + public DbSet Posts { get; set; } public string? DbPath { get; } = string.Empty; public BloggingContext() @@ -42,6 +42,19 @@ public BloggingContext(BloggingContext context, string dbPath) DbPath = dbPath; } + public BloggingContext(string dbPath) + { + Initialize(); + DbPath = dbPath; + } + + + protected virtual void Initialize() + { + Blogs = Set(); + Posts = Set(); + } + //public BloggingContext(string dbPath) //{ // DbPath = dbPath; diff --git "a/\344\272\202\344\270\203\345\205\253\347\263\237/\344\272\202\344\270\203\345\205\253\347\263\237.DataAccessLayer/Program.cs" "b/\344\272\202\344\270\203\345\205\253\347\263\237/\344\272\202\344\270\203\345\205\253\347\263\237.DataAccessLayer/Program.cs" index b451b1f..1f70eab 100644 --- "a/\344\272\202\344\270\203\345\205\253\347\263\237/\344\272\202\344\270\203\345\205\253\347\263\237.DataAccessLayer/Program.cs" +++ "b/\344\272\202\344\270\203\345\205\253\347\263\237/\344\272\202\344\270\203\345\205\253\347\263\237.DataAccessLayer/Program.cs" @@ -25,6 +25,7 @@ public static async Task Main(string[] args) using (var scope = host.Services.CreateScope()) { await using var db = new BloggingContext(); + db.Database.EnsureCreated(); // Note: This sample requires the database to be created before running.