DatabaseExtensionsExecuteMethodQueryTEntity Method

Execute a query stored procedure associated with a method on a data context and return the stored procedure's result set as an enumerable list of the given entity type.

Definition

Namespace: EWSoftware.EntityFramework
Assembly: EWSoftware.EntityFramework (in EWSoftware.EntityFramework.dll) Version: 2025.11.12.0
public static IEnumerable<TEntity> ExecuteMethodQuery<TEntity>(
	this DbContext dataContext,
	MethodInfo methodInfo,
	params Object?[] parameters
)
where TEntity : class, new()

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.

Type Parameters

TEntity
The entity type returned by the query

Return Value

IEnumerableTEntity
An enumerable list of the given entity type.

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 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.

Example

C#
// Execute a search stored procedure and return its result set
public IEnumerable<spTransactionListResult> spTransactionList(int accountKey,
  string? symbol, DateTime fromDate, DateTime toDate, string? txType)
{
    return this.ExecuteMethodQuery<spTransactionListResult>(this.GetMethodInfo(),
        accountKey, symbol, fromDate, toDate, txType);
}

See Also