fix
This commit is contained in:
@@ -17,9 +17,11 @@ public class RepositoryInitializer
|
||||
ConnectionString = connectionString;
|
||||
|
||||
var db = AppDbContextFactory.Instance.CreateDbContext();
|
||||
db.ChangeTracker.QueryTrackingBehavior = QueryTrackingBehavior.NoTracking;
|
||||
db.Database.Migrate();
|
||||
|
||||
Prefill(db);
|
||||
|
||||
UpdateCurrentRates(db);
|
||||
}
|
||||
|
||||
public static ConnectionConfiguration ConnectionString { get; internal set; } = null!;
|
||||
@@ -52,4 +54,28 @@ public class RepositoryInitializer
|
||||
|
||||
dbContext.SaveChanges();
|
||||
}
|
||||
|
||||
private static void UpdateCurrentRates(AppDbContext dbContext)
|
||||
{
|
||||
var lastrates = dbContext.CurrencyRates
|
||||
.Include(x => x.Currency)
|
||||
.GroupBy(x => new
|
||||
{
|
||||
x.CurrencyId,
|
||||
}, (key, g) => g.OrderByDescending(x => x.DateTime).First())
|
||||
.ToList();
|
||||
|
||||
var currencies = dbContext.Currencies.ToList();
|
||||
foreach (var currency in currencies)
|
||||
{
|
||||
var rate = lastrates.FirstOrDefault(x => x.CurrencyId == currency.Id);
|
||||
if (rate != null)
|
||||
{
|
||||
//currency.CurrentRateId = rate.Id;
|
||||
dbContext.Attach(currency);
|
||||
}
|
||||
}
|
||||
|
||||
dbContext.SaveChanges();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user