feat: initial datamodel + ef connection and migrations
Initial version of the data model Includes EF initialization and migrations EF migrations are applied on application start
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using Microsoft.Data.Sqlite;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using TournamentOrganizer.Models;
|
||||
|
||||
namespace TournamentOrganizer;
|
||||
|
||||
public class TournamentContext : DbContext
|
||||
{
|
||||
public DbSet<Event> Events { get; set; }
|
||||
public DbSet<Game> Games { get; set; }
|
||||
public DbSet<Match> Matches { get; set; }
|
||||
public DbSet<TeamParticipant> TeamParticipants { get; set; }
|
||||
public DbSet<PlayerParticipant> PlayerParticipants { get; set; }
|
||||
public DbSet<Player> Players { get; set; }
|
||||
public DbSet<Round> Rounds { get; set; }
|
||||
public DbSet<Team> Teams { get; set; }
|
||||
public DbSet<Tournament> Tournaments { get; set; }
|
||||
|
||||
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
||||
{
|
||||
string datadir = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "TournamentOrganizer");
|
||||
Directory.CreateDirectory(datadir);
|
||||
string dbfile = Path.Combine(datadir, "sqlite.db");
|
||||
optionsBuilder.UseSqlite(new SqliteConnectionStringBuilder()
|
||||
{
|
||||
DataSource = dbfile,
|
||||
Mode = SqliteOpenMode.ReadWriteCreate,
|
||||
ForeignKeys = true,
|
||||
RecursiveTriggers = true
|
||||
}.ToString());
|
||||
}
|
||||
|
||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||
{
|
||||
base.OnModelCreating(modelBuilder);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user