- EF-Implementierungen hinter den Core-Interfaces: EfAccountRepository, EfMarketRepository, EfPositionRepository, EfTradeLogRepository. Thread-safe via IDbContextFactory<CoreDbContext> (kurzlebiger Context je Operation). - AddCorePersistence(DatabaseOptions): Provider "MySql" -> EF + DbContextFactory, "Mongo" -> Mongo-Repos. Program.cs uebergibt die aufgeloesten Optionen. - appsettings.json Provider-Default = "Mongo" (App bleibt vorerst auf MongoDB, kein Verhaltenswechsel). MySQL-Connection liegt in gitignorierter appsettings.Local.json. - Build 0 Fehler. Naechste Stufen: Modul-Context + EF-Repos (inkl. trackers/mt_history), Config-Migration Mongo->MySQL, dann Provider umschalten + Mongo entfernen. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
43 lines
1.3 KiB
C#
43 lines
1.3 KiB
C#
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using PolyTraderSharp.Models;
|
|
|
|
namespace PolyTrader.Core.Persistence.Ef
|
|
{
|
|
public class EfAccountRepository : IAccountRepository
|
|
{
|
|
private readonly IDbContextFactory<CoreDbContext> _factory;
|
|
|
|
public EfAccountRepository(IDbContextFactory<CoreDbContext> factory) => _factory = factory;
|
|
|
|
public List<AccountState> GetAll()
|
|
{
|
|
using var ctx = _factory.CreateDbContext();
|
|
return ctx.Accounts.AsNoTracking().ToList();
|
|
}
|
|
|
|
public void Upsert(AccountState account)
|
|
{
|
|
using var ctx = _factory.CreateDbContext();
|
|
var existing = ctx.Accounts.Find(account.AccountId);
|
|
if (existing == null)
|
|
ctx.Accounts.Add(account);
|
|
else
|
|
ctx.Entry(existing).CurrentValues.SetValues(account);
|
|
ctx.SaveChanges();
|
|
}
|
|
|
|
public void Delete(int accountId)
|
|
{
|
|
using var ctx = _factory.CreateDbContext();
|
|
var existing = ctx.Accounts.Find(accountId);
|
|
if (existing != null)
|
|
{
|
|
ctx.Accounts.Remove(existing);
|
|
ctx.SaveChanges();
|
|
}
|
|
}
|
|
}
|
|
}
|