41 lines
1.4 KiB
C#
41 lines
1.4 KiB
C#
|
|
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);
|
||
|
|
}
|
||
|
|
|
||
|
|
}
|