EF Data Context - Async/Await & Multithreading

后端 未结 3 1725
醉话见心
醉话见心 2020-11-30 20:09

I frequently use async/await to ensure ASP.NET MVC Web API threads are not blocked by longer-running I/O and network operations, specifically database calls

3条回答
  •  广开言路
    2020-11-30 20:46

    The DataContext class is part of LINQ to SQL. It does not understand async/await AFAIK, and should not be used with the Entity Framework async extension methods.

    The DbContext class will work fine with async as long as you are using EF6 or higher; however, you can only have one operation (sync or async) per DbContext instance running at a time. If your code is actually using DbContext, then examine the call stack of your exception and check for any concurrent usage (e.g., Task.WhenAll).

    If you are sure that all access is sequential, then please post a minimal repro and/or report it as a bug to Microsoft Connect.

提交回复
热议问题