rune
Lucas Delanier 2 years ago
commit d566a76284

@ -1,10 +1,11 @@
using Microsoft.EntityFrameworkCore;
using EntityFrameworkLOL.Entities;
using Microsoft.EntityFrameworkCore;
namespace EntityFrameworkLOL
namespace EntityFrameworkLOL.DBContexts
{
class ChampionContext : DbContext
{
public DbSet<ChampionEntity> Champions { get; set; }
public DbSet<ChampionEntity> Champion { get; set; }
protected override void OnConfiguring(DbContextOptionsBuilder options)
=> options.UseSqlite($"Data Source=DBLOL.db");

@ -0,0 +1,13 @@
using EntityFrameworkLOL.Entities;
using Microsoft.EntityFrameworkCore;
namespace EntityFrameworkLOL.DBContexts
{
class RuneContext : DbContext
{
public DbSet<RuneEntity> Rune { get; set; }
protected override void OnConfiguring(DbContextOptionsBuilder options)
=> options.UseSqlite($"Data Source=DBLOL.db");
}
}

@ -0,0 +1,15 @@
using EntityFrameworkLOL.Entities;
using Microsoft.EntityFrameworkCore;
namespace EntityFrameworkLOL.DBContexts
{
class SQLiteContext : DbContext
{
/*public DbSet<ChampionEntity> Champion { get; set; }
public DbSet<SkinEntity> Skin { get; set; }*/
public DbSet<RuneEntity> Rune { get; set; }
protected override void OnConfiguring(DbContextOptionsBuilder options)
=> options.UseSqlite($"Data Source=DBLOL.db");
}
}

@ -0,0 +1,13 @@
using EntityFrameworkLOL.Entities;
using Microsoft.EntityFrameworkCore;
namespace EntityFrameworkLOL.DBContexts
{
class SkinContext : DbContext
{
public DbSet<SkinEntity> Skin { get; set; }
protected override void OnConfiguring(DbContextOptionsBuilder options)
=> options.UseSqlite($"Data Source=DBLOL.db");
}
}

@ -5,8 +5,9 @@ using System.Threading.Tasks;
using System.Collections.Generic;
using System.Text;
using System.ComponentModel.DataAnnotations;
using System.Xml.Linq;
namespace EntityFrameworkLOL
namespace EntityFrameworkLOL.Entities
{
class ChampionEntity
{

@ -0,0 +1,18 @@
using Microsoft.EntityFrameworkCore;
using System;
using System.Linq;
using System.Threading.Tasks;
using System.Collections.Generic;
using System.Text;
using System.ComponentModel.DataAnnotations;
namespace EntityFrameworkLOL.Entities
{
class RuneEntity
{
[Key]
public string Name { get; set; }
public string Description { get; set; }
}
}

@ -0,0 +1,22 @@
using Microsoft.EntityFrameworkCore;
using System;
using System.Linq;
using System.Threading.Tasks;
using System.Collections.Generic;
using System.Text;
using System.ComponentModel.DataAnnotations;
namespace EntityFrameworkLOL.Entities
{
class SkinEntity
{
[Key]
public string Name { get; set; }
public string Description { get; set; }
/*public string Icon { get; set; }
public float Price { get; set; }*/
}
}

@ -20,4 +20,8 @@
</PackageReference>
</ItemGroup>
<ItemGroup>
<Folder Include="Migrations\" />
</ItemGroup>
</Project>

@ -1,5 +1,5 @@
// <auto-generated />
using EntityFrameworkLOL;
using EntityFrameworkLOL.DBContexts;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
@ -9,9 +9,9 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
namespace EntityFrameworkLOL.Migrations
{
[DbContext(typeof(ChampionContext))]
[Migration("20230201163336_MigrationWallah")]
partial class MigrationWallah
[DbContext(typeof(SQLiteContext))]
[Migration("20230202105714_MigrationWallah2")]
partial class MigrationWallah2
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
@ -19,22 +19,18 @@ namespace EntityFrameworkLOL.Migrations
#pragma warning disable 612, 618
modelBuilder.HasAnnotation("ProductVersion", "7.0.2");
modelBuilder.Entity("EntityFrameworkLOL.ChampionEntity", b =>
modelBuilder.Entity("EntityFrameworkLOL.Entities.RuneEntity", b =>
{
b.Property<string>("Name")
.HasColumnType("TEXT");
b.Property<string>("Bio")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("Icon")
b.Property<string>("Description")
.IsRequired()
.HasColumnType("TEXT");
b.HasKey("Name");
b.ToTable("Champions");
b.ToTable("Rune");
});
#pragma warning restore 612, 618
}

@ -5,22 +5,21 @@
namespace EntityFrameworkLOL.Migrations
{
/// <inheritdoc />
public partial class MigrationWallah : Migration
public partial class MigrationWallah2 : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "Champions",
name: "Rune",
columns: table => new
{
Name = table.Column<string>(type: "TEXT", nullable: false),
Bio = table.Column<string>(type: "TEXT", nullable: false),
Icon = table.Column<string>(type: "TEXT", nullable: false)
Description = table.Column<string>(type: "TEXT", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Champions", x => x.Name);
table.PrimaryKey("PK_Rune", x => x.Name);
});
}
@ -28,7 +27,7 @@ namespace EntityFrameworkLOL.Migrations
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "Champions");
name: "Rune");
}
}
}

@ -1,5 +1,5 @@
// <auto-generated />
using EntityFrameworkLOL;
using EntityFrameworkLOL.DBContexts;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
@ -8,30 +8,26 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
namespace EntityFrameworkLOL.Migrations
{
[DbContext(typeof(ChampionContext))]
partial class ChampionContextModelSnapshot : ModelSnapshot
[DbContext(typeof(SQLiteContext))]
partial class SQLiteContextModelSnapshot : ModelSnapshot
{
protected override void BuildModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder.HasAnnotation("ProductVersion", "7.0.2");
modelBuilder.Entity("EntityFrameworkLOL.ChampionEntity", b =>
modelBuilder.Entity("EntityFrameworkLOL.Entities.RuneEntity", b =>
{
b.Property<string>("Name")
.HasColumnType("TEXT");
b.Property<string>("Bio")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("Icon")
b.Property<string>("Description")
.IsRequired()
.HasColumnType("TEXT");
b.HasKey("Name");
b.ToTable("Champions");
b.ToTable("Rune");
});
#pragma warning restore 612, 618
}

@ -1,2 +1,97 @@
// See https://aka.ms/new-console-template for more information
Console.WriteLine("Hello, World!");
using EntityFrameworkLOL.DBContexts;
using EntityFrameworkLOL.Entities;
using System.Linq;
using System;
using System.Text;
class Program
{
static void Main(string[] args)
{
/*ChampionEntity akali = new ChampionEntity {Name="Akali"};
ChampionEntity aatrox = new ChampionEntity { Name = "Aatrox" };
ChampionEntity ahri = new ChampionEntity { Name = "Ahri" };
ChampionEntity bard = new ChampionEntity { Name = "Bard" };
ChampionEntity alistar = new ChampionEntity { Name = "Alistar" };
ChampionEntity akshan = new ChampionEntity { Name = "Akshan" };
using (var context = new ChampionContext())
{
// Crée des champions et les insère dans la base
Console.WriteLine("Creates and inserts new Champions");
context.Add(akali);
context.Add(aatrox);
context.Add(ahri);
context.Add(bard);
context.Add(alistar);
context.Add(akshan);
context.SaveChanges();
Console.WriteLine("Creates and executes a query retrieving the first Champion of the database whose name starts with an \"A\":");
var aChampion = context.Champions
.Where(c => c.Name.StartsWith("A"))
.First();
Console.WriteLine($"{aChampion.Name} (with bio : {aChampion.Bio}");
}*/
RuneEntity conqueror = new RuneEntity { Name = "Conqueror", Description = "" };
RuneEntity thriumph = new RuneEntity { Name = "Thriumph", Description = "" };
RuneEntity alacrity = new RuneEntity { Name = "Legend : Alacrity", Description = "" };
RuneEntity tenacity = new RuneEntity { Name = "Legend : Tenacity", Description = "" };
RuneEntity laststand = new RuneEntity { Name = "Last Stand", Description = "" };
RuneEntity laststand2 = new RuneEntity { Name = "Last Stand 2", Description = "" };
using (var context = new RuneContext())
{
// Crée des Runes et les insère dans la base
Console.WriteLine("Creates and inserts new Runes");
context.Add(conqueror);
context.Add(thriumph);
context.Add(alacrity);
context.Add(tenacity);
context.Add(laststand);
context.Add(laststand2);
context.SaveChanges();
Console.WriteLine("Creates and executes a query retrieving the first Runes of the database whose name starts with an \"L\":");
var lRune = context.Rune
.Where(r => r.Name.StartsWith("L"))
.First();
Console.WriteLine($"{lRune.Name} (with Description : {lRune.Description}");
}
/*SkinEntity stinger = new SkinEntity { Name = "Stinger", Description = "" };
SkinEntity infernal = new SkinEntity { Name = "Infernal", Description = "" };
SkinEntity allStar = new SkinEntity { Name = "All-Star", Description = "" };
SkinEntity justicar = new SkinEntity { Name = "Justicar", Description = "" };
SkinEntity mecha = new SkinEntity { Name = "Mecha", Description = "" };
SkinEntity seaHunter = new SkinEntity { Name = "Sea Hunter", Description = "" };
using (var context = new SkinContext())
{
// Crée des Skins et les insère dans la base
Console.WriteLine("Creates and inserts new Skins");
context.Add(stinger);
context.Add(infernal);
context.Add(allStar);
context.Add(justicar);
context.Add(mecha);
context.Add(seaHunter);
context.SaveChanges();
Console.WriteLine("Creates and executes a query retrieving the first Skins of the database whose name starts with an \"I\":");
var iSkin = context.Skin
.Where(s => s.Name.StartsWith("I"))
.First();
Console.WriteLine($"{iSkin.Name} (with Description : {iSkin.Description}");
Console.WriteLine("Updates the name of the Infernal Skin");
iSkin.Name = "Infernal of Hell (Wallah)";
context.SaveChanges();
Console.WriteLine($"{iSkin.Name} (with Description : {iSkin.Description}");
Console.WriteLine("Deletes one item from the database");
var droid = context.Skin
.SingleOrDefault(s => s.Name.Equals("Infernal"));
context.Remove(droid);
context.SaveChanges();
}*/
}
}

@ -103,4 +103,3 @@ namespace StubLib
}
}
}

Loading…
Cancel
Save