diff --git a/.gitignore b/.gitignore index e28a900..18f8a66 100644 --- a/.gitignore +++ b/.gitignore @@ -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 diff --git a/Sources/Data/EF/DiceAppDbContext.cs b/Sources/Data/EF/DiceAppDbContext.cs new file mode 100644 index 0000000..9422a45 --- /dev/null +++ b/Sources/Data/EF/DiceAppDbContext.cs @@ -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 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); + } + } + */ + + + } +} diff --git a/Sources/Data/EF/Players/PlayerDBContext.cs b/Sources/Data/EF/Players/PlayerDBContext.cs deleted file mode 100644 index 228d52a..0000000 --- a/Sources/Data/EF/Players/PlayerDBContext.cs +++ /dev/null @@ -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 PlayersSet { get; set; } - - protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) - { - optionsBuilder.UseSqlite("Data Source=EFDice.DiceApp.db"); - } - - } -} diff --git a/Sources/Data/EF/Players/PlayerDBManager.cs b/Sources/Data/EF/Players/PlayerDBManager.cs index 663a725..72d5cd4 100644 --- a/Sources/Data/EF/Players/PlayerDBManager.cs +++ b/Sources/Data/EF/Players/PlayerDBManager.cs @@ -7,15 +7,11 @@ using System.Threading.Tasks; namespace Data.EF.Players { - internal class PlayerDBManager : IManager + public class PlayerDBManager : IManager { - PlayerDBContext context = new PlayerDBContext(); public PlayerEntity Add(PlayerEntity toAdd) { - // just to check... - - context.PlayersSet.Add(toAdd); throw new NotImplementedException(); } diff --git a/Sources/Data/EF/Players/PlayerEntity.cs b/Sources/Data/EF/Players/PlayerEntity.cs index 2e178e7..7d5a34f 100644 --- a/Sources/Data/EF/Players/PlayerEntity.cs +++ b/Sources/Data/EF/Players/PlayerEntity.cs @@ -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; } diff --git a/Sources/Data/EF/Players/PlayerExtensions.cs b/Sources/Data/EF/Players/PlayerExtensions.cs index 9aa0441..3aa188d 100644 --- a/Sources/Data/EF/Players/PlayerExtensions.cs +++ b/Sources/Data/EF/Players/PlayerExtensions.cs @@ -2,7 +2,7 @@ namespace Data.EF.Players { - internal static class PlayerExtensions + public static class PlayerExtensions { public static Player ToModel(this PlayerEntity entity) {