Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions 亂七八糟/亂七八糟.DataAccessLayer/BloggingContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ public class BloggingContext : DbContext
//public static readonly BloggingContext Default = new BloggingContext();
//public required DbSet<Blog> Blogs { get; set; }
//public required DbSet<Post>? Posts { get; set; }
public DbSet<Blog>? Blogs { get; set; }
public DbSet<Post>? Posts { get; set; }
public DbSet<Blog> Blogs { get; set; }
public DbSet<Post> Posts { get; set; }
public string? DbPath { get; } = string.Empty;

public BloggingContext()
Expand Down Expand Up @@ -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<Blog>();
Posts = Set<Post>();
}

//public BloggingContext(string dbPath)
//{
// DbPath = dbPath;
Expand Down
1 change: 1 addition & 0 deletions 亂七八糟/亂七八糟.DataAccessLayer/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down