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.
dice_app/Sources/Data/EF/DiceAppDbContext.cs

57 lines
1.4 KiB

using Data.EF.Players;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Data.EF
{
public class DiceAppDbContext : DbContext
{
public DbSet<PlayerEntity> Players { get; set; }
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
=> optionsBuilder.UseSqlite("Data Source=EFDice.DiceApp.db");
/* test with this
> dotnet ef migrations add person_test
> dotnet ef database update
...
using (DiceAppDbContext db = new())
{
db.Players.AddRange(PlayerExtensions.ToEntities(new Player[] {
new("Alice"),
new("Bob"),
new("Clyde"),
new("Fucking Kevin GOSH")
}));
Console.WriteLine("Added, not saved");
if (db.Players is not null)
{
foreach (PlayerEntity p in db.Players)
{
Console.WriteLine(p.ID + " - " + p.Name);
}
}
db.SaveChanges();
Console.WriteLine("Saved");
foreach (PlayerEntity p in db.Players)
{
Console.WriteLine(p.ID + " - " + p.Name);
}
}
*/
}
}