feat: rebuild base repository hierarchy, add readme and agents
- replace EfRepository/BaseDbContext/UtcValueConverter with BaseEfRepository and BaseRepository - add IEfRepository interface hierarchy - consolidate IEntity into Entity.cs, remove standalone IEntity.cs - add PagedResult - adjust all namespaces to HrynCo.DAL.Abstract / HrynCo.DAL.EF - add README.md with solution overview, versioning rules, class diagram - add AGENTS.md Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
@@ -1,10 +1,10 @@
|
||||
namespace HrynCo.DAL.EF.Core;
|
||||
|
||||
using HrynCo.DAL.Abstract;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Storage;
|
||||
|
||||
namespace HrynCo.DAL.EF.Core;
|
||||
|
||||
public abstract class EfUnitOfWork<TDbContext> : IUnitOfWork
|
||||
public class EfUnitOfWork<TDbContext> : IUnitOfWork
|
||||
where TDbContext : DbContext
|
||||
{
|
||||
private readonly TDbContext _context;
|
||||
@@ -15,11 +15,6 @@ public abstract class EfUnitOfWork<TDbContext> : IUnitOfWork
|
||||
_context = context;
|
||||
}
|
||||
|
||||
public Task SaveChangesAsync(CancellationToken cancellationToken = default)
|
||||
{
|
||||
return _context.SaveChangesAsync(cancellationToken);
|
||||
}
|
||||
|
||||
public async Task<ITransaction> BeginTransactionAsync(CancellationToken cancellationToken = default)
|
||||
{
|
||||
if (_currentTransaction != null)
|
||||
@@ -27,13 +22,8 @@ public abstract class EfUnitOfWork<TDbContext> : IUnitOfWork
|
||||
return _currentTransaction;
|
||||
}
|
||||
|
||||
IDbContextTransaction tx = await _context.Database.BeginTransactionAsync(cancellationToken);
|
||||
_currentTransaction = new EfTransactionAdapter(tx);
|
||||
return _currentTransaction;
|
||||
}
|
||||
|
||||
public ITransaction? GetCurrentTransaction()
|
||||
{
|
||||
IDbContextTransaction transaction = await _context.Database.BeginTransactionAsync(cancellationToken);
|
||||
_currentTransaction = new EfTransactionAdapter(transaction);
|
||||
return _currentTransaction;
|
||||
}
|
||||
|
||||
@@ -41,6 +31,7 @@ public abstract class EfUnitOfWork<TDbContext> : IUnitOfWork
|
||||
{
|
||||
ITransaction? existing = GetCurrentTransaction();
|
||||
bool ownsTransaction = existing is null;
|
||||
|
||||
ITransaction tx = existing ?? await BeginTransactionAsync();
|
||||
|
||||
try
|
||||
@@ -73,6 +64,7 @@ public abstract class EfUnitOfWork<TDbContext> : IUnitOfWork
|
||||
{
|
||||
ITransaction? existing = GetCurrentTransaction();
|
||||
bool ownsTransaction = existing is null;
|
||||
|
||||
ITransaction tx = existing ?? await BeginTransactionAsync();
|
||||
|
||||
try
|
||||
@@ -102,4 +94,9 @@ public abstract class EfUnitOfWork<TDbContext> : IUnitOfWork
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public ITransaction? GetCurrentTransaction()
|
||||
{
|
||||
return _currentTransaction;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user