Developer 02 7b7aba6efd Refactor SQL execution classes into new namespace
Restructure and refactor classes related to SQL execution within the `EnvelopeGenerator.Infrastructure` namespace. Key changes include:
- Added `EnvelopeGenerator.Infrastructure.Executor` namespace.
- Moved and redefined `Query`, `QueryExtension`, `SQLExecutor`, `SQLExecutorBaseEntity`, and `SQLExecutorParams` classes to the new namespace.
- Maintained existing functionality while improving code organization and clarity.
2025-05-05 10:54:09 +02:00

32 lines
1.0 KiB
C#

using EnvelopeGenerator.Application.Contracts.SQLExecutor;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;
namespace EnvelopeGenerator.Infrastructure.Executor;
public sealed class SQLExecutor<T> : SQLExecutor, ISQLExecutor<T> where T : class
{
private readonly EGDbContext _context;
private readonly IServiceProvider _provider;
public SQLExecutor(EGDbContext context, IServiceProvider provider, IOptions<SQLExecutorParams> options) : base(provider, options)
{
_context = context;
_provider = provider;
}
public IQuery<T> Execute(string sql, CancellationToken cancellation = default, params object[] parameters)
=> _context
.Set<T>()
.FromSqlRaw(sql, parameters)
.ToQuery();
public IQuery<T> Execute<TSQL>(CancellationToken cancellation = default, params object[] parameters) where TSQL : ISQL<T>
{
var sql = _provider.GetRequiredService<TSQL>();
return Execute(sql.Raw);
}
}