diff --git a/Sources/EFLol/ChampionEntity.cs b/Sources/EFLol/ChampionEntity.cs index b73f713..10e36fe 100644 --- a/Sources/EFLol/ChampionEntity.cs +++ b/Sources/EFLol/ChampionEntity.cs @@ -19,8 +19,7 @@ namespace EFLol //public ReadOnlyDictionary Characteristics { get; private set; } private HashSet skills = new HashSet(); - public Collection Skins { get; set; } - - //public List> championsAndRunePages - } + public Collection Skins { get; set; } + public Collection ListRunePages { get; set; } +} } diff --git a/Sources/EFLol/MyDbContext.cs b/Sources/EFLol/MyDbContext.cs index 8735e18..7358097 100644 --- a/Sources/EFLol/MyDbContext.cs +++ b/Sources/EFLol/MyDbContext.cs @@ -11,9 +11,10 @@ namespace EFLol { public DbSet Champions { get; set; } public DbSet Skins { get; set; } - public DbSet Runes { get; set; } - - public MyDbContext() + public DbSet Runes { get; set; } + public DbSet RunePages { get; set; } + + public MyDbContext() { } public MyDbContext(DbContextOptions options) @@ -32,8 +33,11 @@ namespace EFLol { base.OnModelCreating(modelBuilder); modelBuilder.Entity().Property(c => c.Id).ValueGeneratedOnAdd(); - modelBuilder.Entity().Property(s => s.Id).ValueGeneratedOnAdd(); - - } - } + modelBuilder.Entity().Property(s => s.Id).ValueGeneratedOnAdd(); + + + modelBuilder.Entity().Property(s => s.Id).ValueGeneratedOnAdd(); + modelBuilder.Entity().Property(s => s.Id).ValueGeneratedOnAdd(); + } + } } diff --git a/Sources/EFLol/Program.cs b/Sources/EFLol/Program.cs index a7a69de..89b837e 100644 --- a/Sources/EFLol/Program.cs +++ b/Sources/EFLol/Program.cs @@ -1,65 +1,77 @@ -using System.Collections.ObjectModel; +using System.Collections.Generic; +using System.Collections.ObjectModel; using EFLol; -using (var context = new MyDbContext()) -{ - // Clean the DB before starting - Console.WriteLine("Clean the DB before starting"); - context.Database.EnsureDeleted(); - context.Database.EnsureCreated(); -} - -SkinEntity black = new SkinEntity { Name = "Black", Description = "Black skin", Icon = "black.png", Price = 0.99f }; -SkinEntity white = new SkinEntity { Name = "White", Description = "White skin", Icon = "white.png", Price = 150.99f }; -SkinEntity green = new SkinEntity { Name = "Green", Description = "Green skin", Icon = "green.png", Price = 4.99f }; - -ChampionEntity Zeus = new ChampionEntity -{ - Name = "Zeus", - Bio = "Zeus is the god of the sky", - Skins = new Collection(new List { black, white }) - -}; -ChampionEntity Hera = new ChampionEntity -{ - Name = "Hera", - Bio = "Hera is the goddess of marriage", - Skins = new Collection(new List { green }) - -}; -ChampionEntity Poseidon = new ChampionEntity { Name = "Poseidon", Bio = "Poseidon is the god of the sea" }; - - - -using (var context = new MyDbContext()) -{ - Console.WriteLine("Creates and inserts new Champions"); - context.Add(Zeus); - context.Add(Hera); - context.Add(Poseidon); - context.SaveChanges(); -} - - -using (var context = new MyDbContext()) -{ - foreach (var n in context.Champions) - { - // LINQ to select the skins of the current champion - var skins = context.Champions.Where(c => c.Id == n.Id).SelectMany(c => c.Skins); - - // Display the champion and its skins - Console.WriteLine($"Champion n°{n.Id} - {n.Name} : {skins.Count()} skins"); - } - context.SaveChanges(); -} - -using (var context = new MyDbContext()) -{ - foreach (var n in context.Skins) - { - Console.WriteLine($"Skin n°{n.Id} - {n.Name}" + (n.Price != null ? $" - {n.Price}" : "")); - } - context.SaveChanges(); +internal class Program +{ + private static void Main(string[] args) + { + using (var context = new MyDbContext()) + { + // Clean the DB before starting + Console.WriteLine("Clean the DB before starting"); + context.Database.EnsureDeleted(); + context.Database.EnsureCreated(); + } + + SkinEntity black = new SkinEntity { Name = "Black", Description = "Black skin", Icon = "black.png", Price = 0.99f }; + SkinEntity white = new SkinEntity { Name = "White", Description = "White skin", Icon = "white.png", Price = 150.99f }; + SkinEntity green = new SkinEntity { Name = "Green", Description = "Green skin", Icon = "green.png", Price = 4.99f }; + + RuneEntity rune1 = new RuneEntity { Id = 1, Name = "rune1", Description = "super rune1" }; + RuneEntity rune2 = new RuneEntity { Id = 2, Name = "rune2", Description = "super rune2" }; + RuneEntity rune3 = new RuneEntity { Id = 3, Name = "rune3", Description = "super rune3" }; + + RunePageEntity runePage1 = new RunePageEntity { Id = 1, Name = "runepage1"/*, Runes = new Dictionary { { Category.Major, rune1 } }*/ }; + + ChampionEntity Zeus = new ChampionEntity { Name = "Zeus", Bio = "Zeus is the god of the sky", Skins = new Collection(new List { black, white }) }; + ChampionEntity Hera = new ChampionEntity { Name = "Hera", Bio = "Hera is the goddess of marriage", Skins = new Collection(new List { green }) }; + ChampionEntity Poseidon = new ChampionEntity { + Name = "Poseidon", Bio = "Poseidon is the god of the sea", + ListRunePages = new Collection(new List { { runePage1 } }) + }; + + using (var context = new MyDbContext()) + { + Console.WriteLine("Creates and inserts new Champions"); + context.Add(Zeus); + context.Add(Hera); + context.Add(Poseidon); + context.SaveChanges(); + } + + + using (var context = new MyDbContext()) + { + foreach (var n in context.Champions) + { + // LINQ to select the skins of the current champion + var skins = context.Champions.Where(c => c.Id == n.Id).SelectMany(c => c.Skins); + var runePage = context.Champions.Where(c => c.Id == n.Id).SelectMany(c => c.ListRunePages); + + // Display the champion and its skins + Console.WriteLine($"Champion n°{n.Id} - {n.Name} : {skins.Count()} skins, {runePage.Count()} runePage"); + } + context.SaveChanges(); + } + + using (var context = new MyDbContext()) + { + foreach (var n in context.Skins) + { + Console.WriteLine($"Skin n°{n.Id} - {n.Name}" + (n.Price != null ? $" - {n.Price}" : "")); + } + context.SaveChanges(); + } + + using (var context = new MyDbContext()) + { + foreach (var n in context.RunePages) + { + Console.WriteLine($"runePage n°{n.Id} - {n.Name}"); + } + context.SaveChanges(); + } + } } \ No newline at end of file diff --git a/Sources/EFLol/RuneEntity.cs b/Sources/EFLol/RuneEntity.cs index 934762a..1bd31e3 100644 --- a/Sources/EFLol/RuneEntity.cs +++ b/Sources/EFLol/RuneEntity.cs @@ -11,7 +11,20 @@ namespace EFLol public int Id { get; set; } public string Name { get; set; } public string Description { get; set; } - public RuneFamilyEntity RuneFamily { get; set; } - - } + public RuneFamilyEntity RuneFamily { get; set; } + + public static implicit operator Dictionary(RuneEntity v) + { + throw new NotImplementedException(); + } + } + + public enum RuneFamilyEntity + { + Unknown, + Precision, + Domination + } + } + diff --git a/Sources/EFLol/RuneFamilyEntity.cs b/Sources/EFLol/RuneFamilyEntity.cs deleted file mode 100644 index 47618b8..0000000 --- a/Sources/EFLol/RuneFamilyEntity.cs +++ /dev/null @@ -1,15 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace EFLol -{ - public class RuneFamilyEntity - { - public string Name { get; set; } - public string Description { get; set; } - - } -} diff --git a/Sources/EFLol/RunePageEntity.cs b/Sources/EFLol/RunePageEntity.cs index 04fe543..144f7dd 100644 --- a/Sources/EFLol/RunePageEntity.cs +++ b/Sources/EFLol/RunePageEntity.cs @@ -7,10 +7,10 @@ using System.Threading.Tasks; namespace EFLol { public class RunePageEntity - { - public String Name { get; set; } - public Dictionary Runes { get; set; } - + { + public int Id { get; set; } + public String Name { get; set; } + //public Dictionary Runes { get; set; } } public enum Category