I have a generic repository, in particular, the GetbyId
method, in which I want to change it to return a result with AsNoTracking
or No, as needed. How do I do this?
My Interface:
TEntity GetById(int id, bool @readonly = false);
My Generic Repository:
public class Repository<TEntity> : IRepository<TEntity> where TEntity : class
{
protected readonly RetaguardaContext Db;
protected readonly DbSet<TEntity> DbSet;
public Repository(RetaguardaContext context)
{
Db = context;
DbSet = Db.Set<TEntity>();
}
public virtual TEntity GetById(int id, bool @readonly = false)
{
return DbSet.Find(id);
}
}