Database ExtensionsLoad All AsyncTEntity Method
Load all entities of the given type asynchronously using a stored procedure defined on the entity type
Definition
Namespace: EWSoftware.EntityFramework
Assembly: EWSoftware.EntityFramework (in EWSoftware.EntityFramework.dll) Version: 2025.11.12.0
An enumerable list of the TEntity entities
Assembly: EWSoftware.EntityFramework (in EWSoftware.EntityFramework.dll) Version: 2025.11.12.0
C#
public static IAsyncEnumerable<TEntity> LoadAllAsync<TEntity>(
this DbContext dataContext,
CancellationToken cancellationToken = default
)
where TEntity : class, new()
VB
<ExtensionAttribute>
Public Shared Function LoadAllAsync(Of TEntity As {Class, New}) (
dataContext As DbContext,
Optional cancellationToken As CancellationToken = Nothing
) As IAsyncEnumerable(Of TEntity)C++
public:
[ExtensionAttribute]
generic<typename TEntity>
where TEntity : ref class, gcnew()
static IAsyncEnumerable<TEntity>^ LoadAllAsync(
DbContext^ dataContext,
CancellationToken cancellationToken = CancellationToken()
)F#
[<ExtensionAttribute>]
static member LoadAllAsync :
dataContext : DbContext *
?cancellationToken : CancellationToken
(* Defaults:
let _cancellationToken = defaultArg cancellationToken new CancellationToken()
*)
-> IAsyncEnumerable<'TEntity> when 'TEntity : not struct, new()Parameters
- dataContext DbContext
- The data context to use when loading the entities
- cancellationToken CancellationToken (Optional)
- An optional cancellation token
Type Parameters
- TEntity
- The entity type to load
Return Value
IAsyncEnumerableTEntityAn enumerable list of the TEntity entities
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 LoadAllStoredProcedureAttribute on the entity type. If the attribute is not present, the stored procedure name is assumed to be the same as the entity type name without the ResultSetSuffix property value. The stored procedure should not have any parameters or only parameters with acceptable default values in order to return all rows.
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#
using var dataContext = new MyDbContext();
var watchList = await dataContext.LoadAllAsync<WatchList>().ToListAsync();