fix: inherit EF entities from Entity base class
- TemplateEntity, ProviderEntity, ProviderUsageEntity now inherit Entity (from DAL.Abstract) - Removes duplicated Id, Created, Updated properties from each entity Ref: IT-628 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
@@ -12,12 +12,18 @@ internal sealed class EfTransactionAdapter : ITransaction
|
||||
_transaction = transaction;
|
||||
}
|
||||
|
||||
public Task CommitAsync(CancellationToken cancellationToken = default) =>
|
||||
_transaction.CommitAsync(cancellationToken);
|
||||
public Task CommitAsync(CancellationToken cancellationToken = default)
|
||||
{
|
||||
return _transaction.CommitAsync(cancellationToken);
|
||||
}
|
||||
|
||||
public Task RollbackAsync(CancellationToken cancellationToken = default) =>
|
||||
_transaction.RollbackAsync(cancellationToken);
|
||||
public Task RollbackAsync(CancellationToken cancellationToken = default)
|
||||
{
|
||||
return _transaction.RollbackAsync(cancellationToken);
|
||||
}
|
||||
|
||||
public ValueTask DisposeAsync() =>
|
||||
_transaction.DisposeAsync();
|
||||
}
|
||||
public ValueTask DisposeAsync()
|
||||
{
|
||||
return _transaction.DisposeAsync();
|
||||
}
|
||||
}
|
||||
@@ -18,14 +18,19 @@ internal abstract class EfUnitOfWork<TDbContext> : IUnitOfWork
|
||||
public async Task<ITransaction> BeginTransactionAsync(CancellationToken cancellationToken = default)
|
||||
{
|
||||
if (_currentTransaction != null)
|
||||
{
|
||||
return _currentTransaction;
|
||||
}
|
||||
|
||||
IDbContextTransaction tx = await _context.Database.BeginTransactionAsync(cancellationToken);
|
||||
_currentTransaction = new EfTransactionAdapter(tx);
|
||||
return _currentTransaction;
|
||||
}
|
||||
|
||||
public ITransaction? GetCurrentTransaction() => _currentTransaction;
|
||||
public ITransaction? GetCurrentTransaction()
|
||||
{
|
||||
return _currentTransaction;
|
||||
}
|
||||
|
||||
public async Task ExecuteInTransactionAsync(Func<Task> action)
|
||||
{
|
||||
@@ -36,16 +41,26 @@ internal abstract class EfUnitOfWork<TDbContext> : IUnitOfWork
|
||||
try
|
||||
{
|
||||
await action();
|
||||
if (ownsTransaction) await tx.CommitAsync();
|
||||
if (ownsTransaction)
|
||||
{
|
||||
await tx.CommitAsync();
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
if (ownsTransaction) await tx.RollbackAsync();
|
||||
if (ownsTransaction)
|
||||
{
|
||||
await tx.RollbackAsync();
|
||||
}
|
||||
|
||||
throw;
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (ownsTransaction) await tx.DisposeAsync();
|
||||
if (ownsTransaction)
|
||||
{
|
||||
await tx.DisposeAsync();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -58,17 +73,28 @@ internal abstract class EfUnitOfWork<TDbContext> : IUnitOfWork
|
||||
try
|
||||
{
|
||||
TResult result = await action();
|
||||
if (ownsTransaction) await tx.CommitAsync();
|
||||
if (ownsTransaction)
|
||||
{
|
||||
await tx.CommitAsync();
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
catch
|
||||
{
|
||||
if (ownsTransaction) await tx.RollbackAsync();
|
||||
if (ownsTransaction)
|
||||
{
|
||||
await tx.RollbackAsync();
|
||||
}
|
||||
|
||||
throw;
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (ownsTransaction) await tx.DisposeAsync();
|
||||
if (ownsTransaction)
|
||||
{
|
||||
await tx.DisposeAsync();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -45,9 +45,13 @@ internal abstract class NotificationEfRepository<TEntity>
|
||||
await DbContext.SaveChangesAsync(ct);
|
||||
}
|
||||
|
||||
protected Task<bool> ExistsAsync(Expression<Func<TEntity, bool>> predicate, CancellationToken ct = default) =>
|
||||
DbSet.AnyAsync(predicate, ct);
|
||||
protected Task<bool> ExistsAsync(Expression<Func<TEntity, bool>> predicate, CancellationToken ct = default)
|
||||
{
|
||||
return DbSet.AnyAsync(predicate, ct);
|
||||
}
|
||||
|
||||
protected Task SaveAsync(CancellationToken ct = default) =>
|
||||
DbContext.SaveChangesAsync(ct);
|
||||
}
|
||||
protected Task SaveAsync(CancellationToken ct = default)
|
||||
{
|
||||
return DbContext.SaveChangesAsync(ct);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user