34 lines
1.1 KiB
C#
34 lines
1.1 KiB
C#
using Microsoft.Extensions.Configuration;
|
|
using System.Data.SqlClient;
|
|
using System.Data;
|
|
using Dapper;
|
|
|
|
namespace DataAccess.DbAccess;
|
|
|
|
/// <summary>
|
|
/// Bietet lesenden und schreibenden Zugriff auf eine Datenbank.
|
|
/// </summary>
|
|
public class SqlDataAccess : ISqlDataAccess
|
|
{
|
|
private readonly IConfiguration _config;
|
|
|
|
public SqlDataAccess(IConfiguration config)
|
|
{
|
|
_config = config;
|
|
}
|
|
|
|
public async Task<IEnumerable<TResult>> LoadData<TResult, TParameter>(string storedProcedure, TParameter parameters, string connectionId = "Default")
|
|
{
|
|
using IDbConnection connection = new SqlConnection(_config.GetConnectionString(connectionId));
|
|
|
|
return await connection.QueryAsync<TResult>(storedProcedure, parameters, commandType: CommandType.StoredProcedure);
|
|
}
|
|
|
|
public async Task SaveData<TParameter>(string storedProcedure, TParameter parameters, string connectionId = "Default")
|
|
{
|
|
using IDbConnection connection = new SqlConnection(_config.GetConnectionString(connectionId));
|
|
|
|
await connection.ExecuteAsync(storedProcedure, parameters, commandType: CommandType.StoredProcedure);
|
|
}
|
|
}
|