🚧 WIP
continuous-integration/drone/push Build is passing Details

pull/104/head
Alexis Drai 2 years ago
parent e3687b206e
commit 6a47b33f44

7
.gitignore vendored

@ -4,6 +4,13 @@
##
## Get latest from https://github.com/github/gitignore/blob/main/VisualStudio.gitignore
# Migrations and DB files
# useful while the DB is still fluid, in the early stages
[Mm]igrations/
*.db
*.db-wal
*.db-shm
# User-specific files
*.rsuser
*.suo

@ -0,0 +1,56 @@
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);
}
}
*/
}
}

@ -1,20 +0,0 @@
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Data.EF.Players
{
internal class PlayerDBContext : DbContext
{
public DbSet<PlayerEntity> PlayersSet { get; set; }
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.UseSqlite("Data Source=EFDice.DiceApp.db");
}
}
}

@ -7,15 +7,11 @@ using System.Threading.Tasks;
namespace Data.EF.Players
{
internal class PlayerDBManager : IManager<PlayerEntity>
public class PlayerDBManager : IManager<PlayerEntity>
{
PlayerDBContext context = new PlayerDBContext();
public PlayerEntity Add(PlayerEntity toAdd)
{
// just to check...
context.PlayersSet.Add(toAdd);
throw new NotImplementedException();
}

@ -6,7 +6,7 @@ using System.Threading.Tasks;
namespace Data.EF.Players
{
internal class PlayerEntity
public class PlayerEntity
{
public Guid ID { get; set; }
public string Name { get; set; }

@ -2,7 +2,7 @@
namespace Data.EF.Players
{
internal static class PlayerExtensions
public static class PlayerExtensions
{
public static Player ToModel(this PlayerEntity entity)
{

Loading…
Cancel
Save