You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
3.01-QCM_MuscuMaths/WebApi/DbConnectionLibrairie/MyDbContext.cs

45 lines
1.6 KiB

using Entities;
using Microsoft.EntityFrameworkCore;
namespace DbConnectionLibrairie
{
public class MyDbContext : DbContext
{
public DbSet<AdministratorEntity> Administrators { get; set; }
public DbSet<AnswerEntity> Answers { get; set; }
public DbSet<ChapterEntity> Chapters { get; set; }
public DbSet<LobbyEntity> Lobbies { get; set; }
public DbSet<PlayerEntity> Players { get; set; }
public DbSet<QuestionEntity> Questions { get; set; }
public DbSet<LobbyEntityPlayerEntity> Use { get; set; }
public DbSet<PlayerEntityChapterEntity> Play { get; set; }
public MyDbContext()
{ }
public MyDbContext(DbContextOptions<MyDbContext> contextOptions) :
base(contextOptions)
{ }
protected override void OnConfiguring(DbContextOptionsBuilder options)
{
if (!options.IsConfigured)
{
options.UseSqlite(@"Data source = database.db");
}
}
/// <summary>
/// function overrided OnModelCreating :
/// initialise composed primary keys
/// </summary>
/// <param name="modelBuilder"></param>
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<LobbyEntityPlayerEntity>().HasKey(u => new { u.IdLobby, u.IdPlayer });
modelBuilder.Entity<PlayerEntityChapterEntity>().HasKey(u => new { u.IdPlayer, u.IdChapter });
base.OnModelCreating(modelBuilder);
}
}
}