We save a list of records from one application by removing the list of items and saving the updated list (the list is always less than 10 items):
using (var context = GetContext())
{
EFConfiguration.SuspendExecutionStrategy = true;
using (var dbContextTransaction = context.Database.BeginTransaction())
{
try
{
context.ItemTable.RemoveRange(context.ItemTable.Where(d => d.ForeignKey == foreignKey));
foreach (var item in items)
{
SetTimeStampFields(item);
context.ItemTable.Add(item);
}
int i = await context.SaveChangesAsync();
dbContextTransaction.Commit();
EFConfiguration.SuspendExecutionStrategy = false;
}
catch (Exception)
{
dbContextTransaction.Rollback();
EFConfiguration.SuspendExecutionStrategy = false;
throw;
}
}
}
These changes show up in the database immediately. Then we pull the info from this table from another application:
var itemList = await context.ItemTable.ToListAsync();
The application seems to pickup the updated values when first deployed but afterwards they are stuck to the same values. I have tried adding AsNoTracking() before .ToListAsync() to try and circumvent any cache as this is readonly data but that did not work. The only solution that I have found that gets the data in real time is:
var itemList = await context.ItemTable.SqlQuery("Select * from TableName").ToListAsync();
The table in question holds records with a primary key, two foreign keys, and some timestamp data.
My question is why will the context not pickup the updated values from the table? This issue manifests in local and deployed environments. This is an ASP.NET Core application using Entity Framework 6. The database in question is a mature SQL Server 2012 database that is used across multiple applications without any issues such as this.