From 1c428ee70baa44c90d85d39c7f98041146c5c9bf Mon Sep 17 00:00:00 2001 From: Maxence Lanone Date: Fri, 17 Mar 2023 08:35:49 +0100 Subject: [PATCH] add SkillEntity + LargeImageEntity + RuneEntity + relation oneToOne entre image et champion --- Sources/EntityFrameWorkLib/ChampionEntity.cs | 14 ++++-- .../EntityFrameWorkLib/LargeImageEntity.cs | 21 +++++++++ Sources/EntityFrameWorkLib/LolContext.cs | 45 +++++++++++-------- Sources/EntityFrameWorkLib/SkillEntity.cs | 21 +++++++++ Sources/EntityFrameWorkLib/Skin.cs | 12 ----- Sources/EntityFrameWorkLib/SkinEntity.cs | 22 +++++++++ 6 files changed, 101 insertions(+), 34 deletions(-) create mode 100644 Sources/EntityFrameWorkLib/LargeImageEntity.cs create mode 100644 Sources/EntityFrameWorkLib/SkillEntity.cs delete mode 100644 Sources/EntityFrameWorkLib/Skin.cs create mode 100644 Sources/EntityFrameWorkLib/SkinEntity.cs diff --git a/Sources/EntityFrameWorkLib/ChampionEntity.cs b/Sources/EntityFrameWorkLib/ChampionEntity.cs index d724f42..b3514c7 100644 --- a/Sources/EntityFrameWorkLib/ChampionEntity.cs +++ b/Sources/EntityFrameWorkLib/ChampionEntity.cs @@ -11,10 +11,18 @@ namespace EntityFrameWorkLib [Key] [DatabaseGenerated(DatabaseGeneratedOption.Identity)] public int UniqueId { get; set; } - public string Name { get; set; } + public string Name { get; set; } + + [Required] + [MaxLength(256)] public string Bio { get; set; } + public string Icon { get; set; } - public ChampionClass championClass { get; set; } - } + + [Required] + public ChampionClass Class { get; set; } + + public LargeImageEntity? LargeImageEntity { get; set; } + } } diff --git a/Sources/EntityFrameWorkLib/LargeImageEntity.cs b/Sources/EntityFrameWorkLib/LargeImageEntity.cs new file mode 100644 index 0000000..26d6886 --- /dev/null +++ b/Sources/EntityFrameWorkLib/LargeImageEntity.cs @@ -0,0 +1,21 @@ +using System; +using System.ComponentModel.DataAnnotations; + +namespace EntityFrameWorkLib +{ + public class LargeImageEntity + { + [Key] + public Guid Id { get; set; } + + [Required] + public string Base64 { get; set; } + + [Required] + public int championId { get; set; } + + [Required] + public ChampionEntity champion { get; set; } + } +} + diff --git a/Sources/EntityFrameWorkLib/LolContext.cs b/Sources/EntityFrameWorkLib/LolContext.cs index 89f6651..8d2869c 100644 --- a/Sources/EntityFrameWorkLib/LolContext.cs +++ b/Sources/EntityFrameWorkLib/LolContext.cs @@ -6,32 +6,39 @@ namespace EntityFrameWorkLib { public class LolContext : DbContext { - public DbSet Champions { get; set; } - - public LolContext() { } - public LolContext(DbContextOptions options) - :base(options) - { } - protected override void OnConfiguring(DbContextOptionsBuilder options) - { - if (!options.IsConfigured) - { + public DbSet Champions { get; set; } + public DbSet Skill { get; set; } + public DbSet LargeImage { get; set; } + + public LolContext() { } + public LolContext(DbContextOptions 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) - { - //Définition de la clé primaire de ChampionEntity - modelBuilder.Entity().HasKey(n => n.UniqueId); - //Définition du mode de generation de la clé : génération à l'insertion - modelBuilder.Entity().Property(n => n.UniqueId).ValueGeneratedOnAdd(); + protected override void OnModelCreating(ModelBuilder modelBuilder) + { + //Définition de la clé primaire de ChampionEntity + modelBuilder.Entity().HasKey(n => n.UniqueId); + //Définition du mode de generation de la clé : génération à l'insertion + modelBuilder.Entity().Property(n => n.UniqueId).ValueGeneratedOnAdd(); + + modelBuilder.Entity() + .HasOne(c => c.LargeImageEntity) + .WithOne(li => li.champion) + .HasForeignKey(li => li.championId); - base.OnModelCreating(modelBuilder); + base.OnModelCreating(modelBuilder); } - - } + + } } diff --git a/Sources/EntityFrameWorkLib/SkillEntity.cs b/Sources/EntityFrameWorkLib/SkillEntity.cs new file mode 100644 index 0000000..e0a15e2 --- /dev/null +++ b/Sources/EntityFrameWorkLib/SkillEntity.cs @@ -0,0 +1,21 @@ +using System; +using Shared; +using System.ComponentModel.DataAnnotations; + +namespace EntityFrameWorkLib +{ + public class SkillEntity + { + [Key] + [MaxLength(256)] + public string Name { get; set; } + + [Required] + [MaxLength(500)] + public string Description { get; set; } + + [Required] + public SkillType SkillType { get; set; } + } +} + diff --git a/Sources/EntityFrameWorkLib/Skin.cs b/Sources/EntityFrameWorkLib/Skin.cs deleted file mode 100644 index 6735e2d..0000000 --- a/Sources/EntityFrameWorkLib/Skin.cs +++ /dev/null @@ -1,12 +0,0 @@ -using System; -namespace EntityFrameWorkLib -{ - public class Skin - { - public string Name { get; set; } - public string Description { get; set; } - public string Icon { get; set; } - public float Price { get; set; } - } -} - diff --git a/Sources/EntityFrameWorkLib/SkinEntity.cs b/Sources/EntityFrameWorkLib/SkinEntity.cs new file mode 100644 index 0000000..6be476d --- /dev/null +++ b/Sources/EntityFrameWorkLib/SkinEntity.cs @@ -0,0 +1,22 @@ +using System; +using System.ComponentModel.DataAnnotations; + +namespace EntityFrameWorkLib +{ + public class SkinEntity + { + [Key] + [MaxLength(256)] + public string Name { get; set; } + + [Required] + [MaxLength(500)] + public string Description { get; set; } + + public string Icon { get; set; } + + [Required] + public float Price { get; set; } + } +} +