fix
This commit is contained in:
@@ -118,7 +118,8 @@ public class AppDbContext : DbContext
|
||||
|
||||
modelBuilder.Entity<Currency>()
|
||||
.HasOne(x => x.CurrentRate)
|
||||
.WithOne(x => x.Currency);
|
||||
.WithMany(x => x.Currencies)
|
||||
.HasForeignKey(x => x.CurrentRateId);
|
||||
}
|
||||
|
||||
private void AccountCreating(ModelBuilder modelBuilder)
|
||||
|
||||
@@ -38,6 +38,7 @@ public class AppDbContextFactory : IDesignTimeDbContextFactory<AppDbContext>
|
||||
}
|
||||
|
||||
var db = new AppDbContext(providerEnum, builder.Options);
|
||||
db.ChangeTracker.AutoDetectChangesEnabled = false;
|
||||
db.ChangeTracker.QueryTrackingBehavior = QueryTrackingBehavior.NoTracking;
|
||||
|
||||
return db;
|
||||
|
||||
@@ -55,6 +55,9 @@ public class RepositoryInitializer
|
||||
dbContext.SaveChanges();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Update all currency - set current rate
|
||||
/// </summary>
|
||||
private static void UpdateCurrentRates(AppDbContext dbContext)
|
||||
{
|
||||
var lastrates = dbContext.CurrencyRates
|
||||
@@ -62,7 +65,7 @@ public class RepositoryInitializer
|
||||
.GroupBy(x => new
|
||||
{
|
||||
x.CurrencyId,
|
||||
}, (key, g) => g.OrderByDescending(x => x.DateTime).First())
|
||||
}, (key, g) => g.Where(x => x.DateTime <= DateTime.UtcNow).OrderByDescending(x => x.DateTime).First())
|
||||
.ToList();
|
||||
|
||||
var currencies = dbContext.Currencies.ToList();
|
||||
@@ -71,8 +74,8 @@ public class RepositoryInitializer
|
||||
var rate = lastrates.FirstOrDefault(x => x.CurrencyId == currency.Id);
|
||||
if (rate != null)
|
||||
{
|
||||
//currency.CurrentRateId = rate.Id;
|
||||
dbContext.Attach(currency);
|
||||
currency.CurrentRateId = rate.Id;
|
||||
dbContext.Attach(currency).State = EntityState.Modified;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user