From 82686db38b74549086f6f14e33d826ac267617a0 Mon Sep 17 00:00:00 2001 From: Developer 02 Date: Fri, 19 Dec 2025 09:05:59 +0100 Subject: [PATCH] Add QueryRaw and QueryInterpolated methods to repository Added `QueryRaw` and `QueryInterpolated` methods to the `IRepository` interface for raw and interpolated SQL queries, conditionally compiled for the `NET` target framework. Removed the `Sql` method from `DbRepository` and replaced it with implementations of `QueryRaw` and `QueryInterpolated` using `Entities.FromSqlRaw` and `Entities.FromSqlInterpolated`. Updated the `Query` property in `DbRepository` to use `Entities.AsNoTracking()` for read-only queries. --- .../Repository/IRepository.cs | 10 ++++++++++ DigitalData.Core.Infrastructure/DbRepository.cs | 9 ++++----- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/DigitalData.Core.Abstraction.Application/Repository/IRepository.cs b/DigitalData.Core.Abstraction.Application/Repository/IRepository.cs index 200032d..161c98f 100644 --- a/DigitalData.Core.Abstraction.Application/Repository/IRepository.cs +++ b/DigitalData.Core.Abstraction.Application/Repository/IRepository.cs @@ -63,6 +63,16 @@ namespace DigitalData.Core.Abstraction.Application.Repository #endif IQueryable Query { get; } +#if NET + public +#endif + IQueryable QueryRaw([NotParameterized] string sql, params object[] parameters); + +#if NET + public +#endif + IQueryable QueryInterpolated([NotParameterized] FormattableString sql); + #if NET public #endif diff --git a/DigitalData.Core.Infrastructure/DbRepository.cs b/DigitalData.Core.Infrastructure/DbRepository.cs index 4e8daeb..9043d65 100644 --- a/DigitalData.Core.Infrastructure/DbRepository.cs +++ b/DigitalData.Core.Infrastructure/DbRepository.cs @@ -67,11 +67,6 @@ namespace DigitalData.Core.Infrastructure Mapper = mapper; } - public IQueryable Sql([NotParameterized] string sql, params object[] parameters) - { - return Entities.FromSqlRaw(sql, parameters); - } - #region Create public virtual async Task CreateAsync(TEntity entity, CancellationToken cancel = default) { @@ -105,6 +100,10 @@ namespace DigitalData.Core.Infrastructure #region Read public virtual IQueryable Query => Entities.AsNoTracking(); + public IQueryable QueryRaw([NotParameterized] string sql, params object[] parameters) => Entities.FromSqlRaw(sql, parameters); + + public IQueryable QueryInterpolated([NotParameterized] FormattableString sql) => Entities.FromSqlInterpolated(sql); + public virtual IQueryable Where(Expression> expression) => Entities.AsNoTracking().Where(expression); public virtual IEnumerable GetAll() => Entities.AsNoTracking().ToList();