finition du OneToMany des Skills ! 🎉
continuous-integration/drone/push Build is passing Details

pull/23/head
Pierre Ferreira 2 years ago
parent 5423d0f282
commit f01df10138

@ -32,12 +32,12 @@ namespace EntityFramework
//public ImmutableHashSet<Skill> Skills => skills.ToImmutableHashSet();
//private HashSet<Skill> skills = new HashSet<Skill>();
public ICollection<SkillEntity> Skills { get; set; }
public ICollection<SkillEntity> Skills { get; set; } = new Collection<SkillEntity>();
//public ReadOnlyCollection<SkinEntity> Skins { get; private set; }
//private List<SkinEntity> skins = new();
public ICollection<SkinEntity> skins { get; set; }
public ICollection<SkinEntity> skins { get; set; } = new Collection<SkinEntity>();
//public LargeImageEntity? Image { get; set; } ====> voir pour faire "plus propre" => créé une table pour l'entity Largeimage
public string? Image { get; set; }
@ -69,7 +69,6 @@ namespace EntityFramework
public void RemoveSkill(SkillEntity skill)
=> Skills.Remove(skill);
public bool AddSkin(SkinEntity skin)
{
if (skins.Contains(skin))

@ -0,0 +1,175 @@
// <auto-generated />
using EntityFramework;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
#nullable disable
namespace EntityFramework.Migrations
{
[DbContext(typeof(LoLDBContextWithStub))]
[Migration("20230315145258_myMig")]
partial class myMig
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder.HasAnnotation("ProductVersion", "7.0.2");
modelBuilder.Entity("EntityFramework.ChampionEntity", b =>
{
b.Property<string>("Name")
.HasMaxLength(50)
.HasColumnType("TEXT");
b.Property<string>("Bio")
.IsRequired()
.HasMaxLength(500)
.HasColumnType("string")
.HasColumnName("Bio");
b.Property<string>("Icon")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("Image")
.HasColumnType("TEXT");
b.HasKey("Name");
b.ToTable("Champion", (string)null);
b.HasData(
new
{
Name = "Akali",
Bio = "",
Icon = ""
},
new
{
Name = "Aatrox",
Bio = "",
Icon = ""
},
new
{
Name = "Ahri",
Bio = "",
Icon = ""
},
new
{
Name = "Akshan",
Bio = "",
Icon = ""
},
new
{
Name = "Bard",
Bio = "",
Icon = ""
},
new
{
Name = "Alistar",
Bio = "",
Icon = ""
});
});
modelBuilder.Entity("EntityFramework.LargeImageEntity", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<string>("Base64")
.IsRequired()
.HasColumnType("TEXT");
b.HasKey("Id");
b.ToTable("Image");
});
modelBuilder.Entity("EntityFramework.SkillEntity", b =>
{
b.Property<string>("Name")
.HasColumnType("TEXT");
b.Property<string>("ChampionEntityName")
.HasColumnType("TEXT");
b.Property<string>("Description")
.IsRequired()
.HasColumnType("TEXT");
b.Property<int>("Type")
.HasColumnType("INTEGER");
b.HasKey("Name");
b.HasIndex("ChampionEntityName");
b.ToTable("SkillEntity");
});
modelBuilder.Entity("EntityFramework.SkinEntity", b =>
{
b.Property<string>("Name")
.ValueGeneratedOnAdd()
.HasColumnType("TEXT");
b.Property<string>("ChampionEntityForeignKey")
.HasColumnType("TEXT");
b.Property<string>("Description")
.HasColumnType("TEXT");
b.Property<string>("Icon")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("Image")
.HasColumnType("TEXT");
b.Property<float>("Price")
.HasColumnType("REAL");
b.HasKey("Name");
b.HasIndex("ChampionEntityForeignKey");
b.ToTable("Skins");
});
modelBuilder.Entity("EntityFramework.SkillEntity", b =>
{
b.HasOne("EntityFramework.ChampionEntity", null)
.WithMany("Skills")
.HasForeignKey("ChampionEntityName");
});
modelBuilder.Entity("EntityFramework.SkinEntity", b =>
{
b.HasOne("EntityFramework.ChampionEntity", "Champion")
.WithMany("skins")
.HasForeignKey("ChampionEntityForeignKey");
b.Navigation("Champion");
});
modelBuilder.Entity("EntityFramework.ChampionEntity", b =>
{
b.Navigation("Skills");
b.Navigation("skins");
});
#pragma warning restore 612, 618
}
}
}

@ -0,0 +1,122 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
#pragma warning disable CA1814 // Prefer jagged arrays over multidimensional
namespace EntityFramework.Migrations
{
/// <inheritdoc />
public partial class myMig : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "Champion",
columns: table => new
{
Name = table.Column<string>(type: "TEXT", maxLength: 50, nullable: false),
Bio = table.Column<string>(type: "string", maxLength: 500, nullable: false),
Icon = table.Column<string>(type: "TEXT", nullable: false),
Image = table.Column<string>(type: "TEXT", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_Champion", x => x.Name);
});
migrationBuilder.CreateTable(
name: "Image",
columns: table => new
{
Id = table.Column<int>(type: "INTEGER", nullable: false)
.Annotation("Sqlite:Autoincrement", true),
Base64 = table.Column<string>(type: "TEXT", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Image", x => x.Id);
});
migrationBuilder.CreateTable(
name: "SkillEntity",
columns: table => new
{
Name = table.Column<string>(type: "TEXT", nullable: false),
Type = table.Column<int>(type: "INTEGER", nullable: false),
Description = table.Column<string>(type: "TEXT", nullable: false),
ChampionEntityName = table.Column<string>(type: "TEXT", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_SkillEntity", x => x.Name);
table.ForeignKey(
name: "FK_SkillEntity_Champion_ChampionEntityName",
column: x => x.ChampionEntityName,
principalTable: "Champion",
principalColumn: "Name");
});
migrationBuilder.CreateTable(
name: "Skins",
columns: table => new
{
Name = table.Column<string>(type: "TEXT", nullable: false),
Description = table.Column<string>(type: "TEXT", nullable: true),
Icon = table.Column<string>(type: "TEXT", nullable: false),
Image = table.Column<string>(type: "TEXT", nullable: true),
Price = table.Column<float>(type: "REAL", nullable: false),
ChampionEntityForeignKey = table.Column<string>(type: "TEXT", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_Skins", x => x.Name);
table.ForeignKey(
name: "FK_Skins_Champion_ChampionEntityForeignKey",
column: x => x.ChampionEntityForeignKey,
principalTable: "Champion",
principalColumn: "Name");
});
migrationBuilder.InsertData(
table: "Champion",
columns: new[] { "Name", "Bio", "Icon", "Image" },
values: new object[,]
{
{ "Aatrox", "", "", null },
{ "Ahri", "", "", null },
{ "Akali", "", "", null },
{ "Akshan", "", "", null },
{ "Alistar", "", "", null },
{ "Bard", "", "", null }
});
migrationBuilder.CreateIndex(
name: "IX_SkillEntity_ChampionEntityName",
table: "SkillEntity",
column: "ChampionEntityName");
migrationBuilder.CreateIndex(
name: "IX_Skins_ChampionEntityForeignKey",
table: "Skins",
column: "ChampionEntityForeignKey");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "Image");
migrationBuilder.DropTable(
name: "SkillEntity");
migrationBuilder.DropTable(
name: "Skins");
migrationBuilder.DropTable(
name: "Champion");
}
}
}

@ -0,0 +1,172 @@
// <auto-generated />
using EntityFramework;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
#nullable disable
namespace EntityFramework.Migrations
{
[DbContext(typeof(LoLDBContextWithStub))]
partial class LoLDBContextWithStubModelSnapshot : ModelSnapshot
{
protected override void BuildModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder.HasAnnotation("ProductVersion", "7.0.2");
modelBuilder.Entity("EntityFramework.ChampionEntity", b =>
{
b.Property<string>("Name")
.HasMaxLength(50)
.HasColumnType("TEXT");
b.Property<string>("Bio")
.IsRequired()
.HasMaxLength(500)
.HasColumnType("string")
.HasColumnName("Bio");
b.Property<string>("Icon")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("Image")
.HasColumnType("TEXT");
b.HasKey("Name");
b.ToTable("Champion", (string)null);
b.HasData(
new
{
Name = "Akali",
Bio = "",
Icon = ""
},
new
{
Name = "Aatrox",
Bio = "",
Icon = ""
},
new
{
Name = "Ahri",
Bio = "",
Icon = ""
},
new
{
Name = "Akshan",
Bio = "",
Icon = ""
},
new
{
Name = "Bard",
Bio = "",
Icon = ""
},
new
{
Name = "Alistar",
Bio = "",
Icon = ""
});
});
modelBuilder.Entity("EntityFramework.LargeImageEntity", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<string>("Base64")
.IsRequired()
.HasColumnType("TEXT");
b.HasKey("Id");
b.ToTable("Image");
});
modelBuilder.Entity("EntityFramework.SkillEntity", b =>
{
b.Property<string>("Name")
.HasColumnType("TEXT");
b.Property<string>("ChampionEntityName")
.HasColumnType("TEXT");
b.Property<string>("Description")
.IsRequired()
.HasColumnType("TEXT");
b.Property<int>("Type")
.HasColumnType("INTEGER");
b.HasKey("Name");
b.HasIndex("ChampionEntityName");
b.ToTable("SkillEntity");
});
modelBuilder.Entity("EntityFramework.SkinEntity", b =>
{
b.Property<string>("Name")
.ValueGeneratedOnAdd()
.HasColumnType("TEXT");
b.Property<string>("ChampionEntityForeignKey")
.HasColumnType("TEXT");
b.Property<string>("Description")
.HasColumnType("TEXT");
b.Property<string>("Icon")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("Image")
.HasColumnType("TEXT");
b.Property<float>("Price")
.HasColumnType("REAL");
b.HasKey("Name");
b.HasIndex("ChampionEntityForeignKey");
b.ToTable("Skins");
});
modelBuilder.Entity("EntityFramework.SkillEntity", b =>
{
b.HasOne("EntityFramework.ChampionEntity", null)
.WithMany("Skills")
.HasForeignKey("ChampionEntityName");
});
modelBuilder.Entity("EntityFramework.SkinEntity", b =>
{
b.HasOne("EntityFramework.ChampionEntity", "Champion")
.WithMany("skins")
.HasForeignKey("ChampionEntityForeignKey");
b.Navigation("Champion");
});
modelBuilder.Entity("EntityFramework.ChampionEntity", b =>
{
b.Navigation("Skills");
b.Navigation("skins");
});
#pragma warning restore 612, 618
}
}
}

@ -4,10 +4,10 @@ using Microsoft.EntityFrameworkCore;
using ( var context = new LoLDbContext())
{
context.Add(new ChampionEntity{ Name = "test", Bio = "test", Icon = "test" } );
//context.Add(new ChampionEntity{ Name = "test", Bio = "test", Icon = "test" } );
context.SaveChanges();
ChampionEntity champ = context.Find<ChampionEntity>(1);
ChampionEntity champ = context.Find<ChampionEntity>("Akali");
if( champ != null)
{
@ -23,11 +23,11 @@ using ( var context = new LoLDbContext())
//Test BDD Skills
ChampionEntity champSkill = new ChampionEntity { Name="nomSkill", Bio="bioSkill", Icon="iconSkill" };
SkillEntity s1 = new SkillEntity("Skill1", "desc", SkillType.Unknown);
SkillEntity s2 = new SkillEntity("Skill2", "desc2", SkillType.Ultimate);
SkillEntity s3 = new SkillEntity("Skill3", "desc3", SkillType.Passive);
//SkillEntity s1 = new SkillEntity { Name = "Skill1", Description = "desc", Type = SkillType.Unknown };
SkillEntity s2 = new SkillEntity { Name="Skill2", Description="desc2", Type=SkillType.Ultimate };
SkillEntity s3 = new SkillEntity { Name = "Skill3", Description = "desc3", Type = SkillType.Passive };
champSkill.AddSkill(s1);
champSkill.AddSkill(new SkillEntity { Name = "Skill1", Description = "desc", Type = SkillType.Unknown });
champSkill.AddSkill(s2);
champSkill.AddSkill(s3);

@ -10,42 +10,44 @@ namespace EntityFramework
public class SkillEntity
{
public SkillType Type { get; private set; }
public SkillType Type { get; set; }
[Key]
public string Name
{
get => name;
private init
{
if (string.IsNullOrWhiteSpace(value))
{
throw new ArgumentException("a Skill needs a name");
}
name = value;
}
}
private readonly string name = null!;
public string Name { get; set; }
//public string Name
//{
// get => name;
// private init
// {
// if (string.IsNullOrWhiteSpace(value))
// {
// throw new ArgumentException("a Skill needs a name");
// }
// name = value;
// }
//}
//private readonly string name = null!;
public string Description
{
get => description;
set
{
if (string.IsNullOrWhiteSpace(value))
{
description = "";
return;
}
description = value;
}
}
private string description = "";
public string Description { get; set; }
//public string Description
//{
// get => description;
// set
// {
// if (string.IsNullOrWhiteSpace(value))
// {
// description = "";
// return;
// }
// description = value;
// }
//}
//private string description = "";
public SkillEntity(string Name, string Description, SkillType Type) {
this.name = Name;
this.Description = Description;
this.Type = Type;
}
//public SkillEntity(string Name, string Description, SkillType Type) {
// this.name = Name;
// this.Description = Description;
// this.Type = Type;
//}
}
}

@ -42,7 +42,7 @@ namespace EntityFramework
//}
//private string description = "";
public string Icon { get; set; }
public string Icon { get; set; } = "";
//public LargeImageEntity Image { get; set; }

Loading…
Cancel
Save