3

我正在尝试实现一个通用存储库,如 https://codingblast.com/entity-framework-core-generic-repository/中所述

似乎通用 DbSet 没有实现 AsNoTracking() 方法,我没有使用正确的语法吗?如何解决此问题

public class BaseRepository<TEntity> : IGenericRepository<TEntity>
    where TEntity : class
{
    private readonly DbContext _dbContext;
    public BaseRepository(DbContext dbContext)
    {
        _dbContext = dbContext;
    }

    public IQueryable<TEntity> GetAll()
    {
        return _dbContext.Set<TEntity>().AsNoTracking();
    }

   }
4

1 回答 1

0

这里没有什么需要解决的。
AsNoTracking方法仅以一种一旦被枚举就不会跟踪这些实体的更改的方式配置查询。这在您进行只读且不会在该过程中进行任何编辑时很有用。这样做是为了速度和效率。所以该方法没有可以异步的功能。

枚举查询时将使用异步方法,例如:
ToListAsync()
SingleOrDefaultAsync()

于 2017-10-09T06:29:37.003 回答