4

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?

3 Answers 3

3

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.

Sign up to request clarification or add additional context in comments.

6 Comments

Thankyou for replying @obl Tobl. That is my question.What can be possible difference between the fields inside tblpeople and peopleModel.
Like i already wrote, you can have your tables in the background and additional properties in your model. For example properties you need for calulations or other things, but you don't have to store in database.
So is that possible to store the newly created field in peopleModel.cs in database?
if you want to store in database, just alter your table and update your edmx file (hope i understand you the right way...). After altering and updating your table, the field is in your model automatically.
According to my understanding,model/peopleModel.cs is used for adding new fields to use in program that may not be added in edmx file(Database table). Am I getting it right?
|
2

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.

Comments

1

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.