TopShelfCustomer/TopShelfCustomer.Api/Services/SqlDataAccess.cs
/// <summary>
/// LoadData:
///
/// Acts as a read method for the database.
/// </summary>
/// <typeparam name="T"> The object type to load from the database </typeparam>
/// <typeparam name="U"> The type of the parameters object to query with </typeparam>
/// <param name="storedProcedure"> The SQL procedure to use on the database </param>
/// <param name="parameters"> The parameters for the SQL query </param>
/// <param name="connectionStringName"> The shortened name of the SQL connection string </param>
/// <returns> A list of Type T objects returned from the database query </returns>


Acts as a read method for the database.
Acts as a read method for the database .
public List<T> LoadData<T, U> ( string storedProcedure, U parameters, string connectionStringName ) {
            string connectionString = GetConnectionString( connectionStringName );      
            using ( IDbConnection connection = new SqlConnection( connectionString ) ) {     
                List<T> rows = connection.Query<T>( storedProcedure, parameters,
                    commandType: CommandType.StoredProcedure ).ToList();
                return rows;
            }
        }
public List < T > LoadData < T , U > ( string storedProcedure , U parameters , string connectionStringName ) { string connectionString = GetConnectionString ( connectionStringName ) ; using ( IDbConnection connection = new SqlConnection ( connectionString ) ) { List < T > rows = connection . Query < T > ( storedProcedure , parameters , commandType : CommandType . StoredProcedure ) . ToList ( ) ; return rows ; } }
LoadData:
LoadData :
//The full connection string //Database connection and Query
A list of Type T objects returned from the database query
A list of Type T objects returned from the database query
storedProcedure
string
The SQL procedure to use on the database
The SQL procedure to use on the database
parameters
U
The parameters for the SQL query
The parameters for the SQL query
connectionStringName
string
The shortened name of the SQL connection string
The shortened name of the SQL connection string
typeparam
The object type to load from the database
The object type to load from the database
typeparam
The type of the parameters object to query with
The type of the parameters object to query with