protected internal IEnumerable <TBusinessEntity> ExecuteTableFunction <TBusinessEntity>(string tableFunction, params object[] parameters) where TBusinessEntity : class { using (var conn = new SqlConnection(ConnectionString)) { conn.Open(); using (var sqlcmd = conn.CreateCommand()) { InitSqlCommand(sqlcmd); var sqlparams = new SqlParameter[parameters.Length]; for (int i = 0; i < parameters.Length; i++) { sqlparams[i] = new SqlParameter("@p" + i, parameters[i]); } sqlcmd.CommandType = CommandType.Text; sqlcmd.CommandText = "SELECT * FROM " + tableFunction + "(" + String.Join(",", sqlparams.Select(el => el.ParameterName)) + ")"; sqlcmd.Parameters.AddRange(sqlparams); var reader = sqlcmd.ExecuteReader(); return(ReaderInjection.ReadAll <TBusinessEntity>(reader).ToArray()); } } }
public IEnumerable <TBusinessEntity> ExecuteStoredProcedure <TBusinessEntity>(string storedProcedure, params SqlParameter[] parameters) where TBusinessEntity : class { using (var conn = new SqlConnection(ConnectionString)) { conn.Open(); using (var sqlcmd = conn.CreateCommand()) { InitSqlCommand(sqlcmd); sqlcmd.CommandType = CommandType.StoredProcedure; sqlcmd.CommandText = storedProcedure; foreach (var parameter in parameters) { sqlcmd.Parameters.Add(parameter); } using (var reader = sqlcmd.ExecuteReader()) { return(ReaderInjection.ReadAll <TBusinessEntity>(reader).ToArray()); } } } }
protected internal IEnumerable <TBusinessEntity> ExecuteTableFunction <TBusinessEntity>(string tableFunction, params SqlParameter[] parameters) where TBusinessEntity : class { using (var conn = new SqlConnection(ConnectionString)) { conn.Open(); using (var sqlcmd = conn.CreateCommand()) { InitSqlCommand(sqlcmd); sqlcmd.CommandType = CommandType.Text; sqlcmd.CommandText = "SELECT * FROM " + tableFunction + "(" + String.Join(",", parameters.Select(el => el.ParameterName)) + ")"; foreach (var parameter in parameters) { sqlcmd.Parameters.Add(parameter); } var reader = sqlcmd.ExecuteReader(); return(ReaderInjection.ReadAll <TBusinessEntity>(reader).ToArray()); } } }