forked from ddrilling/AsbCloudServer
add AsNoTracking() in cache
This commit is contained in:
commit
7eed929f33
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user