public static IAsyncEnumerable<TEntity> ExecuteMethodQueryAsync<TEntity>(
this DbContext dataContext,
MethodInfo methodInfo,
Object?[] parameters,
CancellationToken cancellationToken = default
)
where TEntity : class, new()
<ExtensionAttribute>
Public Shared Function ExecuteMethodQueryAsync(Of TEntity As {Class, New}) (
dataContext As DbContext,
methodInfo As MethodInfo,
parameters As Object(),
Optional cancellationToken As CancellationToken = Nothing
) As IAsyncEnumerable(Of TEntity)public:
[ExtensionAttribute]
generic<typename TEntity>
where TEntity : ref class, gcnew()
static IAsyncEnumerable<TEntity>^ ExecuteMethodQueryAsync(
DbContext^ dataContext,
MethodInfo^ methodInfo,
array<Object^>^ parameters,
CancellationToken cancellationToken = CancellationToken()
)[<ExtensionAttribute>]
static member ExecuteMethodQueryAsync :
dataContext : DbContext *
methodInfo : MethodInfo *
parameters : Object[] *
?cancellationToken : CancellationToken
(* Defaults:
let _cancellationToken = defaultArg cancellationToken new CancellationToken()
*)
-> IAsyncEnumerable<'TEntity> when 'TEntity : not struct, new()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 loading the entities. If change tracking is enabled on the data context, changes to the entities will be tracked. If not or the entity is marked with the NeverTrackAttribute, they will not be tracked.
// Execute a search stored procedure and return its result set. The stored procedure name
// is inferred from the method name without the "Async" suffix.
public IAsyncEnumerable<spTransactionListResult> spTransactionListAsync(int accountKey,
string? symbol, DateTime fromDate, DateTime toDate, string? txType)
{
// Note that we can't pass a cancellation token as it would look like one of
// the method parameters. Use the WithCancellation() extension method on the
// call to this method instead.
return this.ExecuteMethodQueryAsync<spTransactionListResult>(this.GetMethodInfo(),
[accountKey, symbol, fromDate, toDate, txType]);
}
// We can't pass the cancellation token to the query method as it will look like
// a parameter to the stored procedure. We need to use the WithCancellation()
// extension method instead.
var cts = new CancellationTokenSource();
await foreach(var t in dc.spTransactionListAsync(1, "MSFT", fromDate,
toDate, null).WithCancellation(cts.Token))
{
....
}