在实体框架查询的何处放置AsNoTracking?

时间:2019-04-04 17:57:19

标签: entity-framework-core

我有以下Entity Framework Core 2.2查询:

IQueryable<Job> jobs = _context.Jobs.AsNoTracking();

jobs = jobs.Where(x => x.Active);

jobs.Skip(offset).Take(limit);

var result = jobs
  .Select(x => new {
    Id = x.Id,
    Country = new {
      Code = x.Country.Code,
      Name = x.Country.Name
    },
    JobTypes = _context.JobTypes.Select(x => x.Name),
    Created = x.Created,
    Skills = x.JobSkills.Select(y => new {
      Id = y.Skill.Id,
      Name = y.Skill.Name
    })
  });

return await result.ToListAsync();

我正在使用AsNoTracking()来加快查询速度。问题是:

在特定位置放置AsNoTracking()吗?

我应该将其放在ToListAsync之前而不是在开头吗?

0 个答案:

没有答案