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.
44 lines
1.6 KiB
44 lines
1.6 KiB
using System;
|
|
using System.Data.Common;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using Model;
|
|
|
|
namespace EntityFrameworkLib
|
|
{
|
|
public class LolContext : DbContext
|
|
{
|
|
public DbSet<ChampionEntity> Champions { get; set; }
|
|
public DbSet<CharacteristicEntity> Characteristics { get; set; }
|
|
public DbSet<SkinEntity> Skins { get; set; }
|
|
public DbSet<SkillEntity> Skills { get; set; }
|
|
public DbSet<LargeImageEntity> Images { get; set; }
|
|
public DbSet<RuneEntity> Runes { get; set; }
|
|
public DbSet<RunePageEntity> RunesPage { get; set; }
|
|
public DbSet<RunePageRuneEntity> RunePageRunes { get; set; }
|
|
public LolContext() { }
|
|
public LolContext(DbContextOptions<LolContext> options)
|
|
: base(options) { }
|
|
|
|
protected override void OnConfiguring(DbContextOptionsBuilder options)
|
|
{
|
|
if (!options.IsConfigured)
|
|
{
|
|
base.OnConfiguring(options.UseSqlite($"DataSource=projet.Champions.db"));
|
|
}
|
|
}
|
|
|
|
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
|
{
|
|
base.OnModelCreating(modelBuilder);
|
|
|
|
modelBuilder.Entity<LargeImageEntity>().Property(l => l.Id).ValueGeneratedOnAdd();
|
|
modelBuilder.Entity<CharacteristicEntity>().HasKey(c => new { c.Name, c.ChampionForeignKey });
|
|
modelBuilder.Entity<RunePageRuneEntity>().HasKey(c => new { c.RunePageName, c.RuneName });
|
|
|
|
modelBuilder.Entity<ChampionEntity>()
|
|
.HasMany(c => c.RunePages)
|
|
.WithMany(r => r.Champions);
|
|
}
|
|
}
|
|
}
|