add AsNoTracking() in cache

This commit is contained in:
Фролов 2021-08-10 16:35:31 +05:00
commit 7eed929f33

View File

@ -26,7 +26,7 @@ namespace AsbCloudInfrastructure.Services.Cache
{
if (cached.Any())
cached.Clear();
var dbEntities = context.Set<TEntity>().ToList();
var dbEntities = context.Set<TEntity>().AsNoTracking().ToList();
cached.AddRange(dbEntities);
data.refreshDate = DateTime.Now;
return cached.Count;
@ -36,7 +36,7 @@ namespace AsbCloudInfrastructure.Services.Cache
{
if (cached.Any())
cached.Clear();
var dbEntities = await context.Set<TEntity>().ToListAsync(token).ConfigureAwait(false);
var dbEntities = await context.Set<TEntity>().AsNoTracking().ToListAsync(token).ConfigureAwait(false);
cached.AddRange(dbEntities);
data.refreshDate = DateTime.Now;
return cached.Count;
@ -225,7 +225,7 @@ namespace AsbCloudInfrastructure.Services.Cache
foreach (var entity in entities)
{
Microsoft.EntityFrameworkCore.ChangeTracking.EntityEntry<TEntity> updated;
if (dbSet.Contains(entity))
if (dbSet.Contains(entity)) // TODO: это очень ммедленно
updated = dbSet.Update(entity);
else
updated = dbSet.Add(entity);