I have the following question about using the Entity Framework.
I have an abstract class for the class that communicates with the base. Aiming for the performance I want instead of bringing all records from a table to after filtering, I want to filter them before bringing.
public abstract class BaseRepository<TEntity> where TEntity : class
{
protected DbContext context;
protected DbSet<TEntity> dbSet;
public BaseRepository(DbContext context)
{
this.context = context;
this.dbSet = context.Set<TEntity>();
}
public virtual IEnumerable<TEntity> GetAll()
{
return this.dbSet.AsQueryable();
}
}
public class MovimentoTratamentoRepo : BaseRepository<MovimentoTratamento>
{
public MovimentoTratamentoRepo() : base(new PegasusOdsContext()) { }
public IQueryable<MovimentoTratamento> GetMovimentoTratamento()
{
return context.Set<MovimentoTratamento>();
}
}
And then call it like this:
GetMovimentoTratamento().Where(x=>x.nome == nome).ToList();
or
GetAll().Where(x=>x.nome == nome).ToList();
Is there a difference between the two methods? Is this the best way to do this?