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.
78 lines
3.8 KiB
78 lines
3.8 KiB
using DTO;
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
namespace EntityFramwork
|
|
{
|
|
public class BDDContext : DbContext
|
|
{
|
|
|
|
public BDDContext() { }
|
|
public BDDContext(DbContextOptions<BDDContext> option) : base(option) { }
|
|
|
|
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
|
{
|
|
base.OnModelCreating(modelBuilder);
|
|
|
|
//création de la table Champion
|
|
modelBuilder.Entity<EntityChampions>().HasKey(a => a.Id);
|
|
modelBuilder.Entity<EntityChampions>().Property(a => a.Id)
|
|
.ValueGeneratedOnAdd();
|
|
modelBuilder.Entity<EntityChampions>().HasIndex(a => a.Name)
|
|
.IsUnique(true);
|
|
//Clé avec skins
|
|
modelBuilder.Entity<EntityChampions>()
|
|
.HasMany(e => e.Skins)
|
|
.WithOne(e => e.Champion)
|
|
.HasForeignKey(e => e.ChampionForeignKey);
|
|
// -------------------------------------------------------------------------------//
|
|
//création de la table Skins
|
|
modelBuilder.Entity<EntitySkins>().HasKey(m => m.Id);
|
|
modelBuilder.Entity<EntitySkins>().Property(m => m.Id)
|
|
.ValueGeneratedOnAdd();
|
|
|
|
modelBuilder.Entity<EntityChampions>()
|
|
.HasMany(e => e.Skins)
|
|
.WithOne(e => e.Champion)
|
|
.HasForeignKey(e => e.ChampionForeignKey);
|
|
|
|
// -------------------------------------------------------------------------------//
|
|
//création de la table Images
|
|
modelBuilder.Entity<EntityLargeImage>().HasKey(c => c.Id);
|
|
modelBuilder.Entity<EntityLargeImage>().Property(c => c.Id)
|
|
.ValueGeneratedOnAdd();
|
|
//Relation Images et Champion
|
|
modelBuilder.Entity<EntityLargeImage>()
|
|
.HasOne(e => e.Champion)
|
|
.WithOne(z => z.Image)
|
|
.HasForeignKey<EntityChampions>(x => x.ImageId);
|
|
//Relation Images et Skins
|
|
modelBuilder.Entity<EntityLargeImage>()
|
|
.HasOne(e => e.Skin)
|
|
.WithOne(z => z.Image)
|
|
.HasForeignKey<EntitySkins>(x => x.ImageId);
|
|
//Relation Images et Rune
|
|
modelBuilder.Entity<EntityLargeImage>()
|
|
.HasOne(e => e.Rune)
|
|
.WithOne(z => z.Image)
|
|
.HasForeignKey<EntityRunes>(x => x.ImageId);
|
|
// -------------------------------------------------------------------------------//
|
|
//création de la table Runes
|
|
modelBuilder.Entity<EntityRunes>().HasKey(c => c.Id);
|
|
modelBuilder.Entity<EntityRunes>().Property(c => c.Id)
|
|
.ValueGeneratedOnAdd();
|
|
}
|
|
|
|
public DbSet<EntityChampions> Champions { get; set; }
|
|
public DbSet<EntitySkins> Skins { get; set; }
|
|
public DbSet<EntityLargeImage> Images { get; set; }
|
|
public DbSet<EntityRunes> Runes { get; set; }
|
|
|
|
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
|
{
|
|
if (!optionsBuilder.IsConfigured)
|
|
{
|
|
optionsBuilder.UseSqlite($"Data Source=C:\\Users\\Jolys Enzo\\home\\BUT\\Projet\\LOL-API\\Sources\\EntityFramwork\\BDD-APILOL.db");
|
|
}
|
|
}
|
|
}
|
|
} |