I've recently been reading Microsoft's tutorial on ASP.NET Core and seen that the controller classes of that tutorial include LINQ queries to fetch data from a database. A code snippet of that tutrorial for example looks like this:
// GET: Movies
public async Task<IActionResult> Index(string movieGenre, string searchString)
{
// Use LINQ to get list of genres.
IQueryable<string> genreQuery = from m in _context.Movie
orderby m.Genre
select m.Genre;
var movies = from m in _context.Movie
select m;
if (!string.IsNullOrEmpty(searchString))
{
movies = movies.Where(s => s.Title.Contains(searchString));
}
if (!string.IsNullOrEmpty(movieGenre))
{
movies = movies.Where(x => x.Genre == movieGenre);
}
var movieGenreVM = new MovieGenreViewModel
{
Genres = new SelectList(await genreQuery.Distinct().ToListAsync()),
Movies = await movies.ToListAsync()
};
return View(movieGenreVM);
}
My question is the following: What exactly does a model class contain? In all the articles I read about MVC pattern I am advised to put the functions where I fetch data from a database into a model class. So are they doing a mistake in this tutorial?