In some cases, like ViewModel initialization, we need to execute many queries.
Of course you can basically execute them sequentially but you also can execute each of them using only one HTTP request.
To dot it with WAQS, you can use the ExecuteQueries method:
var result = await _context.ExecuteQueriesAsync(
_context.Products.AsAsyncQueryable().FirstOrDefault()); var suppliers = ((IEnumerable<object>)result).Cast<Supplier>(); var product = (Product)result;
Now, in the server, if the database is not a contention point, it’s better to parallelize the n (2 in our sample) queries.
But, unfortunately, the Entity Framework context is not thread safe and you can’t execute many queries in parallel with the same context (still true with EF6 and async methods).
So the tip is to create many contexts.
In our case, server contexts are stateless and only used to querying / saving data.
So using many context instances is not problem.
So we can execute queries in parallel on the server.
However, if the database is a contention point, parallelizing queries could be an issue for scalability.
So, with WAQS, it’s an option.
The server.waqs file (generated when we ran NuGet package commands) describes generation configuration.
It contains a service element with an option for parallelization:
<Service Parallel="true" />
If Parallel is set to false, queries will be executed sequentially in the server using the same context instance.