You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

67 lines
1.8 KiB

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<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" };
using (var context = new MyDbContext())
{
// Crée des champions et les insère dans la base
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)
{
// Use LINQ to display the skins for each champion
var skins = from s in context.Skins
where n.Id == s.Id
select s;
Console.WriteLine($"Champion n°{n.Id} - {n.Name}");
}
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();
}