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.

55 lines
1.9 KiB

using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.VisualBasic;
using Model;
namespace EFLib
{
public class LolContext : DbContext
{
public DbSet<ChampionEntity> Champions { get; set; }
public DbSet<LargeImageEntity> LargeImages { get; set; }
public LolContext(DbContextOptions<LolContext> options)
: base(options)
{ }
public LolContext()
{ }
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
if (!optionsBuilder.IsConfigured)
{
optionsBuilder.UseSqlite("Data Source=oiseaux.db");
}
}
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
modelBuilder.Entity<LargeImageEntity>()
.HasOne(e => e.Champion)
.WithOne(z => z.LargeImage)
.HasForeignKey<ChampionEntity>(x => x.ImageId);
var image1 = new LargeImageEntity { Id = 1, Base64 = "test1" };
var image2 = new LargeImageEntity { Id = 2, Base64 = "test2" };
var image3 = new LargeImageEntity { Id = 3, Base64 = "test3" };
modelBuilder.Entity<LargeImageEntity>().HasData(image1, image2, image3);
modelBuilder.Entity<ChampionEntity>().HasData(
new ChampionEntity { Id = 1, Name = "Test1", Bio = "Salut", ChampClass = ChampionClass.Fighter, Icon = "bla", ImageId = 1 },
new ChampionEntity { Id = 2, Name = "Test2", Bio = "hey", ChampClass = ChampionClass.Assassin, Icon = "bla", ImageId = 2 },
new ChampionEntity { Id = 3, Name = "Test3", Bio = "coucou", ChampClass = ChampionClass.Tank, Icon = "bla", ImageId = 3 }
);
}
}
}