Difference between models and tables in mvc using entity structure (database first)

I am using mvc / razor with the database of the first database model. What is the difference between creating a model inside a project and a table.

Example: I have peopleModel.cs inside Models/peopleModel.cs I have a table in the edmx file called tblpeople with the same fields. What is the difference between the two?

+4
source share
3 answers

Your tblpeople is an image of your database.
Your peopleModel is an image of your table, you can see it as an extension. For example, here you can add additional properties that you do not have in your database (in other partial classes).

EDIT:

For example, we have a Database-First application with the following db-based class:

 public partial class Product { public byte Type { get; set; } public string Language { get; set; } } 

BUT we should have some more fields for display of the additional information. So, we created another partial class (in a separate file):

 public partial class Product { public Terminology Terminology { get; set; } } 

This way you can update your spreadsheet model from the database and add your extension from the autoupdated edmx file.

+2
source

If you want to use more than one table attribute in one view,

you just need to create the properties of the havin model that you want from the tables, and just bind this model to view, you will get the result.

I think this is not possible with a table. because you can have a view inherited from only one object

+1
source

This confusion relates to blogs, samples, documentation, and ASP.NET MVC project templates.

M stands for Model, which is actually a ViewModel, but the templates assume that your ViewModel is the same as your database model, which almost never takes place.

+1
source

Source: https://habr.com/ru/post/1486237/


All Articles