1
I have the following question about using the Entity Framework.
I have an abstract class for the class that communicates with the base. Aiming at the performance want instead of bringing all the records of a table to then filter, 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 so:
GetMovimentoTratamento().Where(x=>x.nome == nome).ToList();
or
GetAll().Where(x=>x.nome == nome).ToList();
Is there a difference between the two methods? That’s the best way to do it?
If you are interested, read this question. When to use Entity Framework with Repository Pattern?
– Jéf Bueno
What database are you using.
– Luã Govinda Mendes Souza
@Luãgovindamendessouza Sql Server
– Diego Zanardo