one to many : championEntity -> RunePageEntity
continuous-integration/drone/push Build is passing Details

EF2
Bastien OLLIER 2 years ago
parent 56dfa7a5ce
commit 3465261b70

@ -20,7 +20,6 @@ namespace EFLol
private HashSet<SkillEntity> skills = new HashSet<SkillEntity>(); private HashSet<SkillEntity> skills = new HashSet<SkillEntity>();
public Collection<SkinEntity> Skins { get; set; } public Collection<SkinEntity> Skins { get; set; }
public Collection<RunePageEntity> ListRunePages { get; set; }
//public List<Tuple<ChampionEntity, RunePage>> championsAndRunePages
} }
} }

@ -12,6 +12,7 @@ namespace EFLol
public DbSet<ChampionEntity> Champions { get; set; } public DbSet<ChampionEntity> Champions { get; set; }
public DbSet<SkinEntity> Skins { get; set; } public DbSet<SkinEntity> Skins { get; set; }
public DbSet<RuneEntity> Runes { get; set; } public DbSet<RuneEntity> Runes { get; set; }
public DbSet<RunePageEntity> RunePages { get; set; }
public MyDbContext() public MyDbContext()
{ } { }
@ -34,6 +35,9 @@ namespace EFLol
modelBuilder.Entity<ChampionEntity>().Property(c => c.Id).ValueGeneratedOnAdd(); modelBuilder.Entity<ChampionEntity>().Property(c => c.Id).ValueGeneratedOnAdd();
modelBuilder.Entity<SkinEntity>().Property(s => s.Id).ValueGeneratedOnAdd(); modelBuilder.Entity<SkinEntity>().Property(s => s.Id).ValueGeneratedOnAdd();
modelBuilder.Entity<RuneEntity>().Property(s => s.Id).ValueGeneratedOnAdd();
modelBuilder.Entity<RuneEntity>().Property(s => s.Id).ValueGeneratedOnAdd();
} }
} }
} }

@ -1,7 +1,12 @@
using System.Collections.ObjectModel; using System.Collections.Generic;
using System.Collections.ObjectModel;
using EFLol; using EFLol;
internal class Program
{
private static void Main(string[] args)
{
using (var context = new MyDbContext()) using (var context = new MyDbContext())
{ {
// Clean the DB before starting // Clean the DB before starting
@ -14,23 +19,18 @@ SkinEntity black = new SkinEntity { Name = "Black", Description = "Black skin",
SkinEntity white = new SkinEntity { Name = "White", Description = "White skin", Icon = "white.png", Price = 150.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 }; SkinEntity green = new SkinEntity { Name = "Green", Description = "Green skin", Icon = "green.png", Price = 4.99f };
ChampionEntity Zeus = new ChampionEntity RuneEntity rune1 = new RuneEntity { Id = 1, Name = "rune1", Description = "super rune1" };
{ RuneEntity rune2 = new RuneEntity { Id = 2, Name = "rune2", Description = "super rune2" };
Name = "Zeus", RuneEntity rune3 = new RuneEntity { Id = 3, Name = "rune3", Description = "super rune3" };
Bio = "Zeus is the god of the sky",
Skins = new Collection<SkinEntity>(new List<SkinEntity> { black, white })
}; RunePageEntity runePage1 = new RunePageEntity { Id = 1, Name = "runepage1"/*, Runes = new Dictionary<Category, RuneEntity> { { Category.Major, rune1 } }*/ };
ChampionEntity Hera = new ChampionEntity
{
Name = "Hera",
Bio = "Hera is the goddess of marriage",
Skins = new Collection<SkinEntity>(new List<SkinEntity> { green })
ChampionEntity Zeus = new ChampionEntity { Name = "Zeus", Bio = "Zeus is the god of the sky", Skins = new Collection<SkinEntity>(new List<SkinEntity> { black, white }) };
ChampionEntity Hera = new ChampionEntity { Name = "Hera", Bio = "Hera is the goddess of marriage", Skins = new Collection<SkinEntity>(new List<SkinEntity> { green }) };
ChampionEntity Poseidon = new ChampionEntity {
Name = "Poseidon", Bio = "Poseidon is the god of the sea",
ListRunePages = new Collection<RunePageEntity>(new List<RunePageEntity> { { runePage1 } })
}; };
ChampionEntity Poseidon = new ChampionEntity { Name = "Poseidon", Bio = "Poseidon is the god of the sea" };
using (var context = new MyDbContext()) using (var context = new MyDbContext())
{ {
@ -48,9 +48,10 @@ using (var context = new MyDbContext())
{ {
// LINQ to select the skins of the current champion // LINQ to select the skins of the current champion
var skins = context.Champions.Where(c => c.Id == n.Id).SelectMany(c => c.Skins); 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 // Display the champion and its skins
Console.WriteLine($"Champion n°{n.Id} - {n.Name} : {skins.Count()} skins"); Console.WriteLine($"Champion n°{n.Id} - {n.Name} : {skins.Count()} skins, {runePage.Count()} runePage");
} }
context.SaveChanges(); context.SaveChanges();
} }
@ -63,3 +64,14 @@ using (var context = new MyDbContext())
} }
context.SaveChanges(); context.SaveChanges();
} }
using (var context = new MyDbContext())
{
foreach (var n in context.RunePages)
{
Console.WriteLine($"runePage n°{n.Id} - {n.Name}");
}
context.SaveChanges();
}
}
}

@ -13,5 +13,18 @@ namespace EFLol
public string Description { get; set; } public string Description { get; set; }
public RuneFamilyEntity RuneFamily { get; set; } public RuneFamilyEntity RuneFamily { get; set; }
public static implicit operator Dictionary<object, object>(RuneEntity v)
{
throw new NotImplementedException();
}
} }
public enum RuneFamilyEntity
{
Unknown,
Precision,
Domination
} }
}

@ -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; }
}
}

@ -8,9 +8,9 @@ namespace EFLol
{ {
public class RunePageEntity public class RunePageEntity
{ {
public int Id { get; set; }
public String Name { get; set; } public String Name { get; set; }
public Dictionary<Category, RuneEntity> Runes { get; set; } //public Dictionary<Category, RuneEntity> Runes { get; set; }
} }
public enum Category public enum Category

Loading…
Cancel
Save