Reputation: 659
I use mvc/razor with database first model entity framework.. What is the difference between creating a Model inside the project and having table.
Example:
I have peopleModel.cs
inside Models/peopleModel.cs
I Have a table in edmx file ,called tblpeople
with same fields.
What is the difference between them?
Upvotes: 4
Views: 2145
Reputation: 5684
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 more properties you don't 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 need to have some more fields for displaying additional infos. So we created another partial class (in a seperate file):
public partial class Product
{
public Terminology Terminology { get; set; }
}
So you can update your tablemodel from the database and have your extension seperated from the autoupdated edmx
file.
Upvotes: 3
Reputation: 151594
This confusion is attributable to ASP.NET MVC's blogs, samples, documentation and project templates.
The M
stands for Model, which actually is a ViewModel, but the templates assume your ViewModel is the same as your database Model, which hardly ever is the case.
Upvotes: 2
Reputation: 1466
If you want to use more than one table's attribute in a single view,
you just need to create a model havin properties which you want from tables and just bind that model to view, you'll get the result.
I Think With the table, this thing is not possible. because you can have a view inherited from only one object
Upvotes: 1