forked from ddrilling/AsbCloudServer
CacheTable.Insert() methods fix
This commit is contained in:
parent
1dadc96882
commit
f7ed377572
@ -206,7 +206,11 @@ namespace AsbCloudInfrastructure.Services.Cache
|
||||
public async Task<TEntity> UpsertAsync(TEntity entity, CancellationToken token = default)
|
||||
{
|
||||
var dbSet = context.Set<TEntity>();
|
||||
var updated = dbSet.Update(entity);
|
||||
Microsoft.EntityFrameworkCore.ChangeTracking.EntityEntry<TEntity> updated;
|
||||
if (dbSet.Contains(entity))
|
||||
updated = dbSet.Update(entity);
|
||||
else
|
||||
updated = dbSet.Add(entity);
|
||||
await context.SaveChangesAsync(token).ConfigureAwait(false);
|
||||
await RefreshAsync(token).ConfigureAwait(false);
|
||||
return updated.Entity;
|
||||
@ -217,7 +221,14 @@ namespace AsbCloudInfrastructure.Services.Cache
|
||||
var dbSet = context.Set<TEntity>();
|
||||
var upsertedEntries = new List<TEntity>(entities.Count());
|
||||
foreach (var entity in entities)
|
||||
upsertedEntries.Add(dbSet.Update(entity).Entity);
|
||||
{
|
||||
Microsoft.EntityFrameworkCore.ChangeTracking.EntityEntry<TEntity> updated;
|
||||
if (dbSet.Contains(entity))
|
||||
updated = dbSet.Update(entity);
|
||||
else
|
||||
updated = dbSet.Add(entity);
|
||||
upsertedEntries.Add(updated.Entity);
|
||||
}
|
||||
context.SaveChanges();
|
||||
Refresh();
|
||||
return upsertedEntries;
|
||||
@ -228,7 +239,14 @@ namespace AsbCloudInfrastructure.Services.Cache
|
||||
var dbSet = context.Set<TEntity>();
|
||||
var upsertedEntries = new List<TEntity>(entities.Count());
|
||||
foreach (var entity in entities)
|
||||
upsertedEntries.Add(dbSet.Update(entity).Entity);
|
||||
{
|
||||
Microsoft.EntityFrameworkCore.ChangeTracking.EntityEntry<TEntity> updated;
|
||||
if (dbSet.Contains(entity))
|
||||
updated = dbSet.Update(entity);
|
||||
else
|
||||
updated = dbSet.Add(entity);
|
||||
upsertedEntries.Add(updated.Entity);
|
||||
}
|
||||
await context.SaveChangesAsync(token).ConfigureAwait(false);
|
||||
await RefreshAsync(token).ConfigureAwait(false);
|
||||
return upsertedEntries;
|
||||
|
Loading…
Reference in New Issue
Block a user