Why Does Await Not Appear to Prevent Second Operation on EF Context

前端 未结 1 862
情书的邮戳
情书的邮戳 2020-12-19 01:53

Within an ASP.NET MVC Application I\'m recieving the following error message for one of my controller methods that uses my Entity Framework context.

A

相关标签:
1条回答
  • 2020-12-19 02:24

    Avoid lazy loading when using async with Entity Framework. Instead, either load the data you need first, or use Include()'s to ensure the data you need is loaded with the query.

    https://msdn.microsoft.com/en-gb/magazine/dn802603.aspx

    Current State of Async Support

    ... Async support was added to Entity Framework (in the EntityFramework NuGet package) in version 6. You do have to be careful to avoid lazy loading when working asynchronously, though, because lazy loading is always performed synchronously. ...

    (Emphasis mine)

    Also:

    https://entityframework.codeplex.com/wikipage?title=Task-based%20Asynchronous%20Pattern%20support%20in%20EF.#ThreadSafety

    0 讨论(0)
提交回复
热议问题