DatabaseExtensionsExecuteMethodNonQuery Method

Execute a non-query stored procedure associated with a method on a data context and return the stored procedure's return value, number of rows affected, and optionally output parameter values.

Definition

Namespace: EWSoftware.EntityFramework
Assembly: EWSoftware.EntityFramework (in EWSoftware.EntityFramework.dll) Version: 2025.11.12.0
public static (int RowsAffected, int ReturnValue, IReadOnlyDictionary<string, Object> OutputValues) ExecuteMethodNonQuery(
	this DbContext dataContext,
	MethodInfo methodInfo,
	params Object?[] parameters
)

Parameters

dataContext  DbContext
The data context on which to execute the stored procedure
methodInfo  MethodInfo
The method info for the calling method
parameters  Object
Zero or more parameter values to be passed to the stored procedure. These must match the parameter order of the calling data context method.

Return Value

ValueTupleInt32, Int32, IReadOnlyDictionaryString, Object
A tuple containing the number of rows affected assuming the stored procedure is not using SET NOCOUNT ON, the return value of the stored procedure if any, and a dictionary containing any output parameters indexed by method parameter name with the value being the output value from the stored procedure.

Usage Note

In Visual Basic and C#, you can call this method as an instance method on any object of type DbContext. When you use instance method syntax to call this method, omit the first parameter. For more information, see Extension Methods (Visual Basic) or Extension Methods (C# Programming Guide).

Remarks

The stored procedure name is determined by looking for the MethodStoredProcedureAttribute on the calling data context method. If not specified, the stored procedure name is assumed to be the same as the calling method's name.

If the connection is not in an open state, it is opened temporarily while executing the stored procedure.

Example

C#
// Execute a stored procedure and return its return value
public int spStockAdd(string symbol, string assetDescription, decimal currentBid,
  decimal currentAsk, decimal priceChangePercent)
{
    return this.ExecuteMethodNonQuery(this.GetMethodInfo(), symbol, assetDescription,
        currentBid, currentAsk, priceChangePercent).ReturnValue;
}

// Execute a stored procedure and return the number of rows affected
public int spStockDelete(string symbol)
{
    return this.ExecuteMethodNonQuery(this.GetMethodInfo(), symbol).RowsAffected;
}

// Execute a stored procedure and return the output parameters via the ref parameters on
// the method.  We can also return the stored procedure's return value or rows affected.
public int spCheckForEmployeeSchedule(string bidGroup, int entityKey,
  ref bool bidGroupScheduled, ref bool entityScheduled)
{
    var result = this.ExecuteMethodNonQuery(this.GetMethodInfo(), bidGroup, entityKey,
        bidGroupScheduled, entityScheduled);

    bidGroupScheduled = (bool)result.OutputValues[nameof(bidGroupScheduled);
    entityScheduled = (bool)result.OutputValues[nameof(entityScheduled);

    return result.ReturnValue;
}

See Also