what is difference between a Model and an Entity

前端 未结 4 1417
青春惊慌失措
青春惊慌失措 2020-12-04 07:00

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

Entity, Model, DataModel, ViewModel

Can an

4条回答
  •  -上瘾入骨i
    2020-12-04 07:24

    Entity:

    An entity is the representation of a real-world element within Object Relational Mapping (ORM) as the Entity Framework. This representation will be mapped to a table in a database and its attributes will be transformed into columns. An entity is written using a POCO class that is a simple class, as you can see in the following example in C#:

    using System;
    using System.Collections.Generic;
    using System.Text;
    
    namespace MyAplication.Entity
    {
        public class Person
        {
            public long PersonId { get; set; }
            public string Name { get; set; }
            public short Age { get; set; }
        }
    }
    

    Working with UI creation is a complex task. To keep things organized, programmers separate their applications into layers.

    Each layer is responsible for a task and this prevents the code from being messed up. It is in this scenario that the architectural patterns like the MVC and the MVVM appear.

    Model:

    Within the MVC we have a layer responsible for representing the data previously stored, a given could be an instance of a person modeled in the previous example. This layer is the Model. This template will be used to construct the view.

    ViewModel:

    A ViewModel in the MVVM architecture is much like a Model in the MVC architecture. However a ViewModel is a simplified representation of the data with only the information that is required for the construction of a view.

    using System;
    using System.Collections.Generic;
    using System.Text;
    using MyAplication.Web.ViewModel.BaseViewModel;
    
    namespace MyAplication.Web.ViewModel.Person
    {
        public class PersonNameViewModel : BaseViewModel
        {
            //I just neet the name
            public string Name { get; set; }
        }
    }
    

    DataModel:

    It is simply an abstract model (this model is different from the MVC layer model) which establishes the relationships that exist between the elements that represent real-world entities. It is a very comprehensive subject.

提交回复
热议问题