Quote:
I check this to return data from model direct it return 5 rows as below as below:
var cinmas2 = _context.Cinemas.ToList();
but from view model on step 4 as below no rows displayed:
public IQueryable<CinimaViewModels> GetAllCinimas()
{
var cinmas = new Cinema();
var response = new List<CinimaViewModels>
{
new CinimaViewModels
{
Description=cinmas.Description,
Logo=cinmas.Logo,
Name=cinmas.Name
}
};
return response.AsQueryable();
}
So you have one piece of code which works to return your five cinemas. But you chose to ignore that, and instead create a list containing a single
CinimaViewModels
instance copied from a blank
Cinema
instance.
And you seriously can't see what the problem is?
Use the working code that you already have to get the
Cinema
instances. Then use that to populate your sequence of
CinimaViewModels
instances.
public IQueryable<CinimaViewModels> GetAllCinimas()
{
return _context.Cinemas.Select(cinema => new CinimaViewModels
{
Description = cinema.Description,
Logo = cinema.Logo,
Name = cinema.Name,
});
}