Bring only certain amounts of MVC bank information

Asked

Viewed 43 times

0

I need to bring only 6 records from the database to show in the View, instead of bringing only 6 records, bringing all.

The code is as follows::

public PartialViewResult Cursos()
{
    ViewBag.Cursos = new CursoRepositorio().BuscarTodos().Take(6).ToArray();
    return PartialView();
}
  • Can you show the find all function? and the partial view

  • To seek all is public IEnumerable<TEntity> BuscarTodos()&#xA; {&#xA; return Db.Set<TEntity>().ToList();&#xA; } and the partial view only has a foreach that assembles you with the 6 data of the bank, nothing more

  • Big mistake!!! once you have been in the database and returned all the data ((((Return Db.Set<Tentity>().Tolist()))) try to change this with the amount you want before launching the query against the database.

  • Another major failure caused by trying to implement Repository Pattern on top of EF.

1 answer

1

In your Entity Framework query you need to specify how many records will be listed ...

Try to create an object

DaoCurso

And use a list of that course

List<DaoCurso> curso = null;

curso = entity.TBCURSO.Select(x=> new DaoCurso() { idcurso =x.idcurso , nomecurso = x.nomecurso ).Take(6).ToList();

And add that to your Viewbag;

ViewBag.Cursos = curso;

Browser other questions tagged

You are not signed in. Login or sign up in order to post.