Fix CrudServiceBase.Insert*: set "Id" prop to 0 before inserrt.

This commit is contained in:
Фролов 2021-10-14 17:13:57 +05:00
parent 2173f6593f
commit b9eaf36a65

View File

@ -84,13 +84,19 @@ namespace AsbCloudInfrastructure.Services
public virtual Task<int> InsertAsync(TDto item, CancellationToken token = default) public virtual Task<int> InsertAsync(TDto item, CancellationToken token = default)
{ {
var entity = Convert(item); var entity = Convert(item);
entity.Id = 0;
dbSet.Add(entity); dbSet.Add(entity);
return context.SaveChangesAsync(token); return context.SaveChangesAsync(token);
} }
public virtual Task<int> InsertRangeAsync(IEnumerable<TDto> items, CancellationToken token = default) public virtual Task<int> InsertRangeAsync(IEnumerable<TDto> items, CancellationToken token = default)
{ {
var entities = items.Select(i => Convert(i)); var entities = items.Select(i => {
var entity = Convert(i);
entity.Id = 0;
return entity;
});
dbSet.AddRange(entities); dbSet.AddRange(entities);
return context.SaveChangesAsync(token); return context.SaveChangesAsync(token);
} }