2
0
Files
dotnet-interview-exercise/show-posts/PostsDbContext.cs
Simon Dellenbach f1c0021ad3 Use a local SQLite3 backend instead of PostgreSQL Docker container.
* The provided SQLite3 database contains the required schemas, but no data and can be reset to if required.
* Remove all references to PostgreSQL in documentation and configuration.
* Replace native sqlite3 command with a console app to remove dependency on SQLite3 installation.
2026-02-17 16:25:49 +01:00

21 lines
687 B
C#

using Microsoft.EntityFrameworkCore;
public class PostsDbContext : DbContext
{
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
var currentDir = System.IO.Directory.GetCurrentDirectory();
int showPostsIndex = currentDir.IndexOf("show-posts");
if (showPostsIndex > -1)
{
// Running from the bin directory, get the parent of "show-posts".
currentDir = currentDir.Substring(0, showPostsIndex - 1);
}
string repoRoot = currentDir;
optionsBuilder.UseSqlite($"Data Source={repoRoot}/service/service.db;Mode=ReadOnly;");
}
public DbSet<Post> Posts { get; set; }
}