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.
39 lines
1.1 KiB
39 lines
1.1 KiB
using System;
|
|
using System.Collections.Generic;
|
|
using System.Data.Common;
|
|
using System.Reflection.Emit;
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
namespace EntityFrameWorkLib
|
|
{
|
|
public class TrekContext : DbContext
|
|
{
|
|
public DbSet<PlayerEntity> Players { get; set; }
|
|
|
|
public TrekContext() { }
|
|
public TrekContext(DbContextOptions<TrekContext> options)
|
|
: base(options)
|
|
{ }
|
|
protected override void OnConfiguring(DbContextOptionsBuilder options)
|
|
{
|
|
if (!options.IsConfigured)
|
|
{
|
|
base.OnConfiguring(options.UseSqlite($"DataSource=projet.Players.db"));
|
|
}
|
|
}
|
|
|
|
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
|
{
|
|
//Définition de la clé primaire de PlayerEntity
|
|
modelBuilder.Entity<PlayerEntity>().HasKey(n => n.PlayerId);
|
|
//Définition du mode de generation de la clé : génération à l'insertion
|
|
modelBuilder.Entity<PlayerEntity>().Property(n => n.PlayerId).ValueGeneratedOnAdd();
|
|
|
|
base.OnModelCreating(modelBuilder);
|
|
|
|
}
|
|
|
|
}
|
|
}
|
|
|