Entity Framework Classic QueryFuture

Description

Every time an immediate method like ToList or FirstOrDefault is invoked on a query, a database round trip is made to retrieve data. While most applications don't have performance issues with making multiple round trips, batching multiple queries into one can be critical for some heavy traffic applications for scalability.

EF Classic Query Future opens up all batching future queries features for Entity Framework users.

To batch multiple queries, simply append Future or FutureValue method to the query. All future queries will be stored in a pending list, and when the first future query requires a database round trip, all queries will be resolved in the same SQL command.

Provider Supported

  • SQL Server

Future

Example

// CREATE a pending list of future queries
var customers = context.Customers.Future();
var ActiveCustomers = context.Customers.Where(x => x.IsActive).Future();

// TRIGGER all pending queries in one database round trip			
FiddleHelper.WriteTable("Customers", customers.ToList());		
FiddleHelper.WriteTable("Active Customers", ActiveCustomers);

Try it

Documentation

QueryFutureManager

Properties
Name Description Default Example
IsEnabled Gets or sets if the QueryFuture feature is enabled. true Try it

QueryFutureEnumerable

The QueryFutureEnumerable<TEntityType> inherit from the IEnumerable<T> interfaces.

Methods
Name Description Example
ToArrayAsync() Converts this object to an array asynchronous.
ToArrayAsync(CancellationToken cancellationToken) Converts this object to an array asynchronous.
ToListAsync() Converts this object to a list asynchronous.
ToListAsync(CancellationToken cancellationToken) Converts this object to a list asynchronous.

QueryFutureValue

Properties
Name Description Default Example
Value Gets the value of the future query. null Try it
Methods
Name Description Example
ValueAsync() Gets the value of the future query.
ValueAsync(CancellationToken cancellationToken) Gets the value of the future query.

In this Page