Add project files.
This commit is contained in:
31
EmployeeLibrary/Data/SqlDataAccess.cs
Normal file
31
EmployeeLibrary/Data/SqlDataAccess.cs
Normal file
@ -0,0 +1,31 @@
|
||||
using Dapper;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Data.SqlClient;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace EmployeeLibrary.Data;
|
||||
|
||||
public class SqlDataAccess : ISqlDataAccess
|
||||
{
|
||||
private readonly IConfiguration _config;
|
||||
|
||||
public SqlDataAccess(IConfiguration config)
|
||||
{
|
||||
_config = config;
|
||||
}
|
||||
|
||||
public async Task<List<T>> LoadDataAsync<T, U>(string sql,
|
||||
U parameters,
|
||||
string connectionStringName = "Default")
|
||||
{
|
||||
|
||||
using IDbConnection connection = new SqlConnection(_config.GetConnectionString(connectionStringName));
|
||||
var rows = await connection.QueryAsync<T>(sql, parameters, commandType: CommandType.StoredProcedure);
|
||||
return rows.ToList();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user