feat(IQueryExecutor): IQuery umbenennen

This commit is contained in:
Developer 02 2025-04-30 16:49:26 +02:00
parent 1e54b775a2
commit adbfd69418
6 changed files with 23 additions and 23 deletions

View File

@ -1,12 +1,12 @@
namespace EnvelopeGenerator.Application.Contracts.SQLExecutor;
/// <summary>
/// Provides methods for executing common Entity Framework queries on a given entity type.
/// This interface abstracts away the direct usage of Entity Framework methods for querying data
/// Provides methods for executing common queries on a given entity type.
/// This interface abstracts away the direct usage of ORM libraries (such as Entity Framework) for querying data
/// and provides asynchronous and synchronous operations for querying a collection or single entity.
/// </summary>
/// <typeparam name="TEntity">The type of the entity being queried.</typeparam>
public interface IQueryExecutor<TEntity>
public interface IQuery<TEntity>
{
/// <summary>
/// Asynchronously retrieves the first entity or a default value if no entity is found.

View File

@ -8,20 +8,20 @@
public interface ISQLExecutor<TEntity>
{
/// <summary>
/// Executes a raw SQL query and returns an <see cref="IQueryExecutor{TEntity}"/> for further querying operations on the result.
/// Executes a raw SQL query and returns an <see cref="IQuery{TEntity}"/> for further querying operations on the result.
/// </summary>
/// <param name="sql">The raw SQL query to execute.</param>
/// <param name="cancellation">Optional cancellation token for the operation.</param>
/// <param name="parameters">Optional parameters for the SQL query.</param>
/// <returns>An <see cref="IQueryExecutor{TEntity}"/> instance for further query operations on the result.</returns>
IQueryExecutor<TEntity> Execute(string sql, CancellationToken cancellation = default, params object[] parameters);
/// <returns>An <see cref="IQuery{TEntity}"/> instance for further query operations on the result.</returns>
IQuery<TEntity> Execute(string sql, CancellationToken cancellation = default, params object[] parameters);
/// <summary>
/// Executes a custom SQL query defined by a class that implements <see cref="ISQL{TEntity}"/> and returns an <see cref="IQueryExecutor{TEntity}"/> for further querying operations on the result.
/// Executes a custom SQL query defined by a class that implements <see cref="ISQL{TEntity}"/> and returns an <see cref="IQuery{TEntity}"/> for further querying operations on the result.
/// </summary>
/// <typeparam name="TSQL">The type of the custom SQL query class implementing <see cref="ISQL{TEntity}"/>.</typeparam>
/// <param name="cancellation">Optional cancellation token for the operation.</param>
/// <param name="parameters">Optional parameters for the SQL query.</param>
/// <returns>An <see cref="IQueryExecutor{TEntity}"/> instance for further query operations on the result.</returns>
IQueryExecutor<TEntity> Execute<TSQL>(CancellationToken cancellation = default, params object[] parameters) where TSQL : ISQL<TEntity>;
/// <returns>An <see cref="IQuery{TEntity}"/> instance for further query operations on the result.</returns>
IQuery<TEntity> Execute<TSQL>(CancellationToken cancellation = default, params object[] parameters) where TSQL : ISQL<TEntity>;
}

View File

@ -4,11 +4,11 @@ using Microsoft.EntityFrameworkCore;
namespace EnvelopeGenerator.Infrastructure;
public sealed record QueryExecutor<TEntity> : IQueryExecutor<TEntity>
public sealed record Query<TEntity> : IQuery<TEntity>
{
private readonly IQueryable<TEntity> _query;
internal QueryExecutor(IQueryable<TEntity> queryable)
internal Query(IQueryable<TEntity> queryable)
{
_query = queryable;
}

View File

@ -1,9 +0,0 @@
namespace EnvelopeGenerator.Infrastructure;
public static class QueryExecutorExtension
{
public static QueryExecutor<TEntity> ToExecutor<TEntity>(this IQueryable<TEntity> queryable) where TEntity : class
{
return new QueryExecutor<TEntity>(queryable);
}
}

View File

@ -0,0 +1,9 @@
namespace EnvelopeGenerator.Infrastructure;
public static class QueryExtension
{
public static Query<TEntity> ToQuery<TEntity>(this IQueryable<TEntity> queryable) where TEntity : class
{
return new Query<TEntity>(queryable);
}
}

View File

@ -16,13 +16,13 @@ public sealed class SQLExecutor<T> : ISQLExecutor<T> where T : class
_provider = provider;
}
public IQueryExecutor<T> Execute(string sql, CancellationToken cancellation = default, params object[] parameters)
public IQuery<T> Execute(string sql, CancellationToken cancellation = default, params object[] parameters)
=> _context
.Set<T>()
.FromSqlRaw(sql, parameters)
.ToExecutor();
.ToQuery();
public IQueryExecutor<T> Execute<TSQL>(CancellationToken cancellation = default, params object[] parameters) where TSQL : ISQL<T>
public IQuery<T> Execute<TSQL>(CancellationToken cancellation = default, params object[] parameters) where TSQL : ISQL<T>
{
var sql = _provider.GetRequiredService<TSQL>();
return Execute(sql.Raw);