What is the difference between a Model and an Entity?

datamodel entity entity-framework model viewmodel


I am confused to understand what is the meaning of this words:

Entity, Model, DataModel, ViewModel

Can any body help me to understanding them please? Thank you all.

1/5/2012 2:20:16 PM

Accepted Answer

I hope I've not missed your point here king.net...

Anyway, presuming you're talking about entity modelling or entity-relationship modelling (ERDs):

  • an entity represents any real world entity - e.g. student, course,
  • an entity will have attributes - e.g. student has first name, surname, date-of-birth
  • an entity will have relationships - e.g. student "is enrolled on" course (where student and course are entities with attributes and "is enrolled on" is the relationship.
  • the relationship may be "one-to-one", "one-to-many" or "many-to-many" - e.g. one student "is enrolled on" many courses and similarly one course "has" many students.
  • relationships also have cardinality

Adding relationships between entities creates a "data model". You've modeled some real world system and the internal entities/ objects in that system. Next step is to normalise it to ensure it meets "normal form".

In ERD terms, you may have "logical" and "physical" models. The logical describes the data-model in simple high-level terms that witholds the technical detail required to implement it. It represents the system solution overview. The physical model includes technical details required to actually implement the system (such as "many-to-many join tables" needed to implement "many-to-many" relationships).

Here are some tutorials on-line (though I'm sure there must be thousands):

I'm not quite sure what you mean by "model" and "view model" in a related context. Not sure if you may be confusing this with Model-View-Controller paradigm (MVC). Here, a model is some data component and the view represents an observer of that data (such as a table or graph UI component). There's lots on-line explaining "model view controller" or "MVC".

Hope this helps, Wayne

1/5/2012 2:59:43 PM

Popular Answer

The definition of these terms is quite ambiguous. You will find different definitions at different places.

Entity: An entity represents a single instance of your domain object saved into the database as a record. It has some attributes that we represent as columns in our tables.

Model: A model typically represents a real world object that is related to the problem or domain space. In programming, we create classes to represent objects. These classes, known as models, have some properties and methods (defining objects behavior).

ViewModel: The term ViewModel originates from the MVVM (Model View ViewModel) design pattern. There are instances in which the data to be rendered by the view comes from two different objects. In such scenarios, we create a model class which consists of all properties required by the view. It’s not a domain model but a ViewModel because, a specific view uses it. Also, it doesn’t represent a real world object.

DataModel: In order to solve a problem, objects interact with each other. Some objects share a relationship among them and consequently, form a data model that represents the objects and the relationship between them.

In an application managing customer orders, for instance, if we have a customer and order object then these objects share a many to many relationship between them. The data model is eventually dependent on the way our objects interact with each other. In a database, we see the data model as a network of tables referring to some other tables.

To know more about object relationships visit my blog post: Basics of Object Relationships

For more details visit my blog post: Entity vs Model vs ViewModel vs DataModel

Related Questions


Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow