In MVC, 1 model 1 tables or 1 model several tables?
I am building an application that contain 3 tables. I don’t know whether I should create one model for all 3 tables or create 3 models for 3 tables.
In the case I use 3 models for 3 tables, where should I put the code if I want to join these 3 tables? Put the code in any one of 3 models?
Any suggestions?
Usually you will create one model per table, so in your case it means you need 3 models.
When i say “Model” i mean a class that will represent a single row (usually) in a single table.
for example:
Tables:
in such case the most easy and simple is to create 3 different classes (which represents the data model of the application) where the first class represents a single product the next represents an order and the last class will represent a single customer.