Add generic DbRepository for raw SQL execution

Introduced DbRepository<TDbContext> to provide basic database operations, including methods for executing raw SQL commands via ExecuteSqlRaw and ExecuteSqlInterpolated. The class exposes the underlying DbContext for use in derived classes. Existing DbRepository<TDbContext, TEntity> remains unchanged.
This commit is contained in:
2025-12-18 13:44:45 +01:00
parent bf418e986b
commit 6717aa37ab

View File

@@ -19,6 +19,26 @@ namespace DigitalData.Core.Infrastructure
{
#endif
public class DbRepository<TDbContext> where TDbContext : DbContext
{
protected internal readonly TDbContext Context;
public DbRepository(TDbContext context)
{
Context = context;
}
public int ExecuteSqlRaw([NotParameterized] string sql, params object[] parameters)
{
return Context.Database.ExecuteSqlRaw(sql, parameters);
}
public int ExecuteSqlInterpolated(FormattableString sql)
{
return Context.Database.ExecuteSqlInterpolated(sql);
}
}
public class DbRepository<TDbContext, TEntity> : IRepository<TEntity> where TDbContext : DbContext where TEntity : class
{
protected internal readonly TDbContext Context;