In some MVC frameworks I've used the Model has the method and SQL in the Model so that if you call the controller, it invokes a method on the model class (say Products), and it returns the data. In ASP.NET MVC Core, from what I have seen so far, there is a separate file besides the model to do the logic. Do I use two classes? They appear (the ones I read) to be using the Repository Pattern.
public class Product
{
public int ProductId { get; set; }
public string Name { get; set; }
public int Quantity { get; set; }
public double Price { get; set; }
}
That's one class. Where do the methods to get the data go? Is the Repository Pattern necessary or it is a "Best Practice"?
public interface IStoreRepository
{
//CRUD signatures
}
public ProductRepository : IStoreRepository
{
//CRUD implementation
}
....
public IActionResult Products()
{
//A controller
//Call method in ProductRepository.GetAll or the like
}
If it matters I am attempting to use Dapper, not EF.