Database ExtensionsExecute Method Non Query Async Method
Execute a non-query stored procedure associated with a method on a data context asynchronously 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
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.
Assembly: EWSoftware.EntityFramework (in EWSoftware.EntityFramework.dll) Version: 2025.11.12.0
C#
public static Task<(int RowsAffected, int ReturnValue, IReadOnlyDictionary<string, Object> OutputValues)> ExecuteMethodNonQueryAsync(
this DbContext dataContext,
MethodInfo methodInfo,
Object?[] parameters,
CancellationToken cancellationToken = default
)VB
<ExtensionAttribute>
Public Shared Function ExecuteMethodNonQueryAsync (
dataContext As DbContext,
methodInfo As MethodInfo,
parameters As Object(),
Optional cancellationToken As CancellationToken = Nothing
) As Task(Of (RowsAffected As Integer, ReturnValue As Integer, OutputValues As IReadOnlyDictionary(Of String, Object)))C++
public:
[ExtensionAttribute]
static Task<ValueTuple<int, int, IReadOnlyDictionary<String^, Object^>^>>^ ExecuteMethodNonQueryAsync(
DbContext^ dataContext,
MethodInfo^ methodInfo,
array<Object^>^ parameters,
CancellationToken cancellationToken = CancellationToken()
)F#
[<ExtensionAttribute>]
static member ExecuteMethodNonQueryAsync :
dataContext : DbContext *
methodInfo : MethodInfo *
parameters : Object[] *
?cancellationToken : CancellationToken
(* Defaults:
let _cancellationToken = defaultArg cancellationToken new CancellationToken()
*)
-> Task<ValueTuple<int, int, IReadOnlyDictionary<string, Object>>> 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.
- cancellationToken CancellationToken (Optional)
- An optional cancellation token
Return Value
TaskValueTupleInt32, Int32, IReadOnlyDictionaryString, ObjectA 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 method name ends with the AsyncMethodSuffix value, the indicated suffix is removed from the method name to get the stored procedure name.
If the connection is not in an open state, it is opened temporarily while executing the stored procedure.
Example
C#
// The stored procedure names are inferred from the method names without the "Async" suffix.
// Execute a stored procedure and return its return value asynchronously
public async int spStockAddAsync(string symbol, string assetDescription,
decimal currentBid, decimal currentAsk, decimal priceChangePercent)
{
var result = await this.ExecuteMethodNonQueryAsync(this.GetMethodInfo(), [symbol,
assetDescription, currentBid, currentAsk, priceChangePercent]);
return result.ReturnValue;
}
// Execute a stored procedure and return the number of rows affected
public async int spStockDeleteAsync(string symbol)
{
var result = await this.ExecuteMethodNonQueryAsync(this.GetMethodInfo(), [symbol]);
return result.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 async int spCheckForEmployeeScheduleAsync(string bidGroup, int entityKey,
ref bool bidGroupScheduled, ref bool entityScheduled)
{
var result = await this.ExecuteMethodNonQueryAsync(this.GetMethodInfo(), [bidGroup, entityKey,
bidGroupScheduled, entityScheduled]);
bidGroupScheduled = (bool)result.OutputValues[nameof(bidGroupScheduled);
entityScheduled = (bool)result.OutputValues[nameof(entityScheduled);
return result.ReturnValue;
}