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.
123 lines
6.3 KiB
123 lines
6.3 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(x => x.ChampionId);
|
|
//Clé avec skill
|
|
modelBuilder.Entity<EntityChampions>()
|
|
.HasMany(e => e.Skills)
|
|
.WithOne(e => e.Champions)
|
|
.HasForeignKey(x => x.ChampionId);
|
|
|
|
// -------------------------------------------------------------------------------//
|
|
//création de la table Skins
|
|
modelBuilder.Entity<EntitySkins>().HasKey(m => m.Id);
|
|
modelBuilder.Entity<EntitySkins>().Property(m => m.Id)
|
|
.ValueGeneratedOnAdd();
|
|
|
|
// -------------------------------------------------------------------------------//
|
|
//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();
|
|
|
|
modelBuilder.Entity<EntityRunes>().HasMany(e => e.CategorieRune)
|
|
.WithOne(e => e.Rune)
|
|
.HasForeignKey(e => e.IdRune);
|
|
// -------------------------------------------------------------------------------//
|
|
//création de la table Skills
|
|
modelBuilder.Entity<EntitySkill>().HasKey(c => c.Id);
|
|
modelBuilder.Entity<EntitySkill>().Property(c => c.Id)
|
|
.ValueGeneratedOnAdd();
|
|
|
|
// -------------------------------------------------------------------------------//
|
|
//création de la table Page rune
|
|
modelBuilder.Entity<EntityPageRune>().HasKey(c => c.Id);
|
|
modelBuilder.Entity<EntityPageRune>().Property(c => c.Id)
|
|
.ValueGeneratedOnAdd();
|
|
|
|
modelBuilder.Entity<EntityPageRune>().HasMany(e => e.CategorieRune)
|
|
.WithOne(e => e.PageRune)
|
|
.HasForeignKey(e => e.IdPageRune);
|
|
|
|
// -------------------------------------------------------------------------------//
|
|
//création de la table Categorie_Rune
|
|
modelBuilder.Entity<EntityCategorieRune>().HasKey(c => c.Id);
|
|
modelBuilder.Entity<EntityCategorieRune>().Property(c => c.Id)
|
|
.ValueGeneratedOnAdd();
|
|
|
|
// ---------------------------------- Stub --------------------------------------//
|
|
// Ajout Image
|
|
|
|
int nbImage = 29;
|
|
List<EntityLargeImage> listImage = new List<EntityLargeImage>();
|
|
for( int i=1; i<nbImage+1; i++)
|
|
{
|
|
EntityLargeImage tmpImage = new EntityLargeImage() { Id = i,Base64 = "Inconnu !" };
|
|
listImage.Add(tmpImage);
|
|
}
|
|
modelBuilder.Entity<EntityLargeImage>().HasData(listImage);
|
|
// Ajout Champion
|
|
|
|
|
|
}
|
|
|
|
public DbSet<EntityChampions> Champions { get; set; }
|
|
public DbSet<EntitySkins> Skins { get; set; }
|
|
public DbSet<EntityLargeImage> Images { get; set; }
|
|
public DbSet<EntityRunes> Runes { get; set; }
|
|
public DbSet<EntitySkill> Skills { get; set; }
|
|
public DbSet<EntityPageRune> PageRunes { get; set; }
|
|
public DbSet<EntityCategorieRune> CategorieRunes { get; set; }
|
|
|
|
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
|
{
|
|
if (!optionsBuilder.IsConfigured)
|
|
{
|
|
optionsBuilder.UseSqlite($"Data Source=BDD-APILOL.db");
|
|
}
|
|
}
|
|
}
|
|
} |