Entity Framework Plus Query Future - FutureValue Deferred
Immediate resolution methods like Count() and FirstOrDefault() cannot use future methods since it executes the query immediately.
// Oops! The query is already executed, we cannot delay the execution. var count = ctx.Customers.Count(); // Oops! All customers will be retrieved instead of customer count var count = ctx.Customers.Future().Count();
EF+ Query Deferred has been created to resolve this issue. The resolution is now deferred instead of being immediate which lets you use FutureValue and get the expected result.
// using Z.EntityFramework.Plus; // Don't forget to include this. var ctx = new EntitiesContext(); // GET the first active customer and the number of active customers var futureFirstCustomer = ctx.Customers.DeferredFirstOrDefault().FutureValue(); var futureCustomerCount = ctx.Customers.DeferredCount().FutureValue(); // TRIGGER all pending queries Customer firstCustomer = futureFirstCustomer.Value; // The future query is already resolved and contains the result var count = futureCustomerCount.Value;