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:
@@ -19,6 +19,26 @@ namespace DigitalData.Core.Infrastructure
|
|||||||
{
|
{
|
||||||
#endif
|
#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
|
public class DbRepository<TDbContext, TEntity> : IRepository<TEntity> where TDbContext : DbContext where TEntity : class
|
||||||
{
|
{
|
||||||
protected internal readonly TDbContext Context;
|
protected internal readonly TDbContext Context;
|
||||||
|
|||||||
Reference in New Issue
Block a user