相关疑难解决方法(0)

实体框架核心:在上一个操作完成之前,在此上下文中启动了第二个操作

我正在使用Entity Framework Core开发ASP.Net Core 2.0项目

<PackageReference Include="Microsoft.EntityFrameworkCore" Version="2.0.1" />
  <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="2.0.0" PrivateAssets="All" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="2.0.0"/>
Run Code Online (Sandbox Code Playgroud)

在我的一个列表方法中,我收到此错误:

InvalidOperationException: A second operation started on this context before a previous operation completed. Any instance members are not guaranteed to be thread safe.
Microsoft.EntityFrameworkCore.Internal.ConcurrencyDetector.EnterCriticalSection()
Run Code Online (Sandbox Code Playgroud)

这是我的方法:

    [HttpGet("{currentPage}/{pageSize}/")]
    [HttpGet("{currentPage}/{pageSize}/{search}")]
    public ListResponseVM<ClientVM> GetClients([FromRoute] int currentPage, int pageSize, string search)
    {
        var resp = new ListResponseVM<ClientVM>();
        var items = _context.Clients
            .Include(i => i.Contacts)
            .Include(i => i.Addresses)
            .Include("ClientObjectives.Objective")
            .Include(i => i.Urls)
            .Include(i => i.Users)
            .Where(p => string.IsNullOrEmpty(search) …
Run Code Online (Sandbox Code Playgroud)

c# entity-framework asp.net-web-api

42
推荐指数
10
解决办法
5万
查看次数

标签 统计

asp.net-web-api ×1

c# ×1

entity-framework ×1