Does Entity Framework support parallel async queries?

usr

What happens when we start multiple async Entity Framework queries and run them in parallel?

Are they physically executed in parallel? Are they serialized by Entity Framework? Is this unsupported? Does it result in an exception?

public async Task QueryDatabase()
{
    using (var context = new MyDbContext())
    {
        Task task1 = context.SomeTable1.ToListAsync();
        Task task2 = context.SomeTable2.ToListAsync();

        await Task.WhenAll(task1, task2);
    }
}
ken2k

This is not supported as per the specifications of version 6.

This should throw a DbConcurrencyException exception saying

A second operation started on this context before a previous asynchronous operation completed. Use 'await' to ensure that any asynchronous operations have completed before calling another method on this context. Any instance members are not guaranteed to be thread safe.

EF will detect if the developer attempts to execute two async operations at one time and throw.

From a codeplex page of the project:

Enabling asynchronous execution of database operations is actually orthogonal to enabling concurrent execution on the same context. In the particular case of server scenarios, using concurrent access could affect scalability negatively as it would mean that in order to process a single request you would be spinning of an arbitrary number of different threads. All the threads would compete for resources such as memory with other threads necessary to server other concurrent requests.

Entity Framework Core does not support this scenario either.

EF Core doesn't support multiple parallel operations being run on the same context instance. You should always wait for an operation to complete before beginning the next operation. This is typically done by using the await keyword on each async operation.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Which versions of the Entity Framework support compiled queries?

From Dev

Does Entity Framework 6 support .NET 4.0?

From Dev

Does Entity Framework support Multi-Threading?

From Dev

Analyzing queries by Entity Framework

From Dev

does elasticsearch support queries of queries?

From Dev

Why does using parameterized queries or entity framework prevent sql injection?

From Dev

does entity framework support User Defined Data Types?

From Dev

Does Entity Framework Code First support this kind of mapping?

From Dev

MVC scaffolding does not support Entity Framework 6 or later

From Dev

Does Entity Framework 6.1 support an XML data type natively?

From Dev

Does Entity Framework support differing data types in the model?

From Dev

Does Entity Framework support Oracle 10g?

From Dev

Entity Framework connect to Oracle: ODP for .NET "does not support time"

From Dev

Entity framework 2.0 does not support DNX version 5.0

From Java

Entity Framework Queryable async

From Dev

Nested Async with Entity Framework

From Dev

Async LINQ queries null when using Entity Framework 6 with Azure SQL?

From Dev

Entity Framework 6 - Timing queries

From Dev

Entity Framework generated SQL queries

From Dev

Optimizing Entity Framework queries for import

From Dev

Performance tuning Entity Framework queries

From Dev

Entity Framework IQueryable, with 2 queries

From Dev

Performance tuning Entity Framework queries

From Dev

Does rescore support nested queries?

From Dev

Multiple database support with entity framework

From Dev

Why does Entity Framework fire two SQL queries when simply fetching table rows?

From Dev

Why does Entity Framework create a different sql queries for very similar code

From Dev

Using Entity framework in conjunction with Task Parallel Library

From Dev

Parallelization of queries using multiple Entity Framework contexts

Related Related

  1. 1

    Which versions of the Entity Framework support compiled queries?

  2. 2

    Does Entity Framework 6 support .NET 4.0?

  3. 3

    Does Entity Framework support Multi-Threading?

  4. 4

    Analyzing queries by Entity Framework

  5. 5

    does elasticsearch support queries of queries?

  6. 6

    Why does using parameterized queries or entity framework prevent sql injection?

  7. 7

    does entity framework support User Defined Data Types?

  8. 8

    Does Entity Framework Code First support this kind of mapping?

  9. 9

    MVC scaffolding does not support Entity Framework 6 or later

  10. 10

    Does Entity Framework 6.1 support an XML data type natively?

  11. 11

    Does Entity Framework support differing data types in the model?

  12. 12

    Does Entity Framework support Oracle 10g?

  13. 13

    Entity Framework connect to Oracle: ODP for .NET "does not support time"

  14. 14

    Entity framework 2.0 does not support DNX version 5.0

  15. 15

    Entity Framework Queryable async

  16. 16

    Nested Async with Entity Framework

  17. 17

    Async LINQ queries null when using Entity Framework 6 with Azure SQL?

  18. 18

    Entity Framework 6 - Timing queries

  19. 19

    Entity Framework generated SQL queries

  20. 20

    Optimizing Entity Framework queries for import

  21. 21

    Performance tuning Entity Framework queries

  22. 22

    Entity Framework IQueryable, with 2 queries

  23. 23

    Performance tuning Entity Framework queries

  24. 24

    Does rescore support nested queries?

  25. 25

    Multiple database support with entity framework

  26. 26

    Why does Entity Framework fire two SQL queries when simply fetching table rows?

  27. 27

    Why does Entity Framework create a different sql queries for very similar code

  28. 28

    Using Entity framework in conjunction with Task Parallel Library

  29. 29

    Parallelization of queries using multiple Entity Framework contexts

HotTag

Archive