public List<TElement> SQLQuery<TElement>(string sql, string? connectionStringName = null, params StoredParameter[] parameters) { string ConnectionString = connectionStringName == null ? _ApplicationConfiguration.ConnectionString : _ApplicationConfiguration.GetConnectionString(connectionStringName); using (SqlConnection sqlConn = new SqlConnection(ConnectionString)) { using (SqlCommand cmd = new SqlCommand(sql, sqlConn)) { cmd.CommandText = sql; cmd.CommandType = System.Data.CommandType.StoredProcedure; cmd.CommandTimeout = (int)TimeSpan.FromMinutes(5).TotalSeconds; //cmd.Parameters.AddRange(parameters); foreach (var parameter in parameters) { var paramter = cmd.CreateParameter(); paramter.ParameterName = parameter.ParameterName; paramter.Value = parameter.ParameterValue; if (!string.IsNullOrEmpty(parameter.TypeName)) { paramter.SqlDbType = SqlDbType.Structured; paramter.TypeName = parameter.TypeName; } cmd.Parameters.Add(paramter); } sqlConn.Open(); using (var reader = cmd.ExecuteReader()) { var result = reader.MapToList<TElement>(); sqlConn.Close(); return result; } } }
telement
TElement
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)