#54 Remove InsertAndGetId from repository.

pull/81/head
Halil İbrahim Kalkan 9 years ago
parent ea13ec2c76
commit a459413751

@ -63,23 +63,28 @@ namespace Volo.Abp.Domain.Repositories.EntityFrameworkCore
return DbSet.FindAsync(new object[] { id }, cancellationToken);
}
public override TEntity Insert(TEntity entity)
public override TEntity Insert(TEntity entity, bool autoSave = false)
{
return DbSet.Add(entity).Entity;
}
var savedEntity = DbSet.Add(entity).Entity;
public override TPrimaryKey InsertAndGetId(TEntity entity)
{
var insertedEntity = Insert(entity);
DbContext.SaveChanges();
return insertedEntity.Id;
if (autoSave)
{
DbContext.SaveChanges();
}
return savedEntity;
}
public override async Task<TPrimaryKey> InsertAndGetIdAsync(TEntity entity, CancellationToken cancellationToken = default(CancellationToken))
public override async Task<TEntity> InsertAsync(TEntity entity, bool autoSave = false, CancellationToken cancellationToken = new CancellationToken())
{
var insertedEntity = await InsertAsync(entity, cancellationToken);
await DbContext.SaveChangesAsync(cancellationToken);
return insertedEntity.Id;
var savedEntity = DbSet.Add(entity).Entity;
if (autoSave)
{
await DbContext.SaveChangesAsync(cancellationToken);
}
return savedEntity;
}
public override TEntity Update(TEntity entity)

@ -59,35 +59,24 @@ namespace Volo.Abp.Domain.Repositories
/// Inserts a new entity.
/// </summary>
/// <param name="entity">Inserted entity</param>
/// <param name="autoSave">
/// Set true to automatically save changes to database.
/// This can be used to set database generated Id of an entity for some ORMs (like Entity Framework).
/// </param>
[NotNull]
TEntity Insert([NotNull] TEntity entity);
TEntity Insert([NotNull] TEntity entity, bool autoSave = false);
/// <summary>
/// Inserts a new entity.
/// </summary>
/// <param name="autoSave">
/// Set true to automatically save changes to database.
/// This can be used to set database generated Id of an entity for some ORMs (like Entity Framework).
/// </param>
/// <param name="cancellationToken">A <see cref="T:System.Threading.CancellationToken" /> to observe while waiting for the task to complete.</param>
/// <param name="entity">Inserted entity</param>
[NotNull]
Task<TEntity> InsertAsync([NotNull] TEntity entity, CancellationToken cancellationToken = default(CancellationToken));
/// <summary>
/// Inserts a new entity and gets it's Id.
/// It may require to save current unit of work
/// to be able to retrieve id.
/// </summary>
/// <param name="entity">Entity</param>
/// <returns>Id of the entity</returns>
TPrimaryKey InsertAndGetId([NotNull] TEntity entity);
/// <summary>
/// Inserts a new entity and gets it's Id.
/// It may require to save current unit of work
/// to be able to retrieve id.
/// </summary>
/// <param name="cancellationToken">A <see cref="T:System.Threading.CancellationToken" /> to observe while waiting for the task to complete.</param>
/// <param name="entity">Entity</param>
/// <returns>Id of the entity</returns>
Task<TPrimaryKey> InsertAndGetIdAsync([NotNull] TEntity entity, CancellationToken cancellationToken = default(CancellationToken));
Task<TEntity> InsertAsync([NotNull] TEntity entity, bool autoSave = true, CancellationToken cancellationToken = default(CancellationToken));
/// <summary>
/// Updates an existing entity.

@ -39,21 +39,11 @@ namespace Volo.Abp.Domain.Repositories
return Task.FromResult(Find(id));
}
public abstract TEntity Insert(TEntity entity);
public abstract TEntity Insert(TEntity entity, bool autoSave = false);
public virtual Task<TEntity> InsertAsync(TEntity entity, CancellationToken cancellationToken = default(CancellationToken))
public virtual Task<TEntity> InsertAsync(TEntity entity, bool autoSave = false, CancellationToken cancellationToken = default(CancellationToken))
{
return Task.FromResult(Insert(entity));
}
public virtual TPrimaryKey InsertAndGetId(TEntity entity)
{
return Insert(entity).Id;
}
public virtual Task<TPrimaryKey> InsertAndGetIdAsync(TEntity entity, CancellationToken cancellationToken = default(CancellationToken))
{
return Task.FromResult(InsertAndGetId(entity));
return Task.FromResult(Insert(entity, autoSave));
}
public abstract TEntity Update(TEntity entity);

Loading…
Cancel
Save