protected DbParameter ExecuteStoredProcedure(StoredProcedureRequest request, Action <DbDataReader> readAction, out List <DbParameter> outputParameters) { if (request == null) { throw new ArgumentNullException("request"); } if (string.IsNullOrWhiteSpace(request.CommandText)) { throw new ArgumentNullException("request.CommandText"); } List <DbParameter> outParameters = null; DbParameter returnParameter = null; using (DbDataReader reader = CreateReader(request.CommandText, request.CommandTimeout, request.CommandType, parameters => { parameters.Derive(request.InputParameters); var dbParameters = parameters.Command.Parameters.OfType <DbParameter>(); outParameters = dbParameters.Where(p => (p.Direction == ParameterDirection.InputOutput || p.Direction == ParameterDirection.Output) && !string.IsNullOrEmpty(p.ParameterName)).ToList(); returnParameter = dbParameters.Where(p => p.Direction == ParameterDirection.ReturnValue).FirstOrDefault(); }, 0)) { if (readAction != null) { readAction(reader); } } outputParameters = outParameters; return(returnParameter); }
object ICloneable.Clone() { StoredProcedureRequest cloneRequest = new StoredProcedureRequest(); cloneRequest.CommandText = this.CommandText; cloneRequest.CommandType = this.CommandType; cloneRequest.CommandTimeout = this.CommandTimeout; if (this.InputParameters != null) { cloneRequest.InputParameters = new Dictionary <string, object>(this.InputParameters, StringComparer.OrdinalIgnoreCase); } return(cloneRequest); }
protected StoredProcedureResponse ExecuteStoredProcedure <T>(StoredProcedureRequest request) where T : IDictionary <string, object>, new() { StoredProcedureResponse spResponse = new StoredProcedureResponse(_DynamicObjectXmlSettings); List <DbParameter> outputParameters; DbParameter returnParameter = ExecuteStoredProcedure(request, reader => { bool isFirstResultSetVoid = false; do { spResponse.ResultSets.Add(LoadDynamicData <T>(reader).ToList()); if (spResponse.ResultSets.Count == 1 && reader.FieldCount == 0) { isFirstResultSetVoid = true; } } while (reader.NextResult()); if (spResponse.ResultSets.Count == 1 && spResponse.ResultSets[0].Count == 0 && isFirstResultSetVoid) { spResponse.ResultSets.Clear(); } }, out outputParameters); if (outputParameters != null) { T expandoObject = new T(); foreach (DbParameter op in outputParameters) { expandoObject.Add(op.ParameterName.TrimParameterPrefix(), op.Value); } spResponse.OutputParameters = new BindableDynamicObject(expandoObject, _DynamicObjectXmlSettings); } if (returnParameter != null) { spResponse.ReturnValue = returnParameter.Value; } return(spResponse); }
public object ExecuteStoredProcedure(StoredProcedureRequest request, Action <int> exportResultSetStartTag, Action <DbDataReader> exportHeader, Action <DbDataReader> exportRow, Action <int> exportResultSetEndTag, IDictionary <string, object> outputParametersContainer, int[] resultSetChoices = null, bool bulkRead = false) { List <DbParameter> outputParameters; bool chooseSpecificResultSets = (resultSetChoices != null && resultSetChoices.Length > 0); bool chooseOnlyOneResultSet = (resultSetChoices != null && resultSetChoices.Length == 1); DbParameter returnParameter = ExecuteStoredProcedure(request, reader => { int resultSetIndex = 0; do { if (chooseSpecificResultSets && !resultSetChoices.Contains(resultSetIndex)) { continue; } if (exportResultSetStartTag != null) { exportResultSetStartTag(resultSetIndex); } if (exportHeader != null) { exportHeader(reader); } if (exportRow != null) { if (bulkRead) { exportRow(reader); } else { while (reader.Read()) { exportRow(reader); } } } if (exportResultSetEndTag != null) { exportResultSetEndTag(resultSetIndex); } if (chooseOnlyOneResultSet) { break; } } while (reader.NextResult() && ++resultSetIndex >= 0); }, out outputParameters); if (outputParameters != null && outputParametersContainer != null) { foreach (DbParameter op in outputParameters) { outputParametersContainer.Add(op.ParameterName.TrimParameterPrefix(), op.Value); } } return((returnParameter == null) ? null : returnParameter.Value); }
public StoredProcedureResponse ExecuteStoredProcedure(StoredProcedureRequest request) { return(ExecuteStoredProcedure <ExpandoObject>(request)); }