what is difference between a Model and an Entity

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

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

Entity, Model, DataModel, ViewModel

Can an

4条回答
  •  自闭症患者
    2020-12-04 07:23

    First of all,to know about Entity you must know about Class. All of them represent same fields but the terminology changes based on declaration.

    Let us consider a table from any database[SQL,ORACLE,Informix,Cassandra..] as example.

    CLASS:

    Generally a table is a considered as a class until it is added to edmx or dbmx.

     //Student class
            public class Student()
            {
            //Properties
            public int StudentNumber;
            public string StudentName;
            }
    

    ENTITY:

    • After drag drop/adding the table into dbmx/edmx it is referred to as Entity.

    • Each Entity is generated from its corresponding class and we can add attributes to entity which are used for performing operations using
      linq or entity.

    DATAMODEL:

    • Contains all the fields in table.

    • DATAMODEL is a direct class reference to your cshtml or controller where you can access the attributes to perform CRUD operations.

    VIEWMODEL:

    • Some situations occur where we need to perform CRUD operations more than one model(table).
    • So we combine all our required models in a class and define them in its constructor.

    Example: Lets assume

    //Student class
    public class Student()
    {
    //Properties
    public int StudentNumber;
    public string StudentName;
    }
    //Marks Class
    Public class Marks()
    {
    public int Maths;
    public int Physics;
    public int Chemistry;
    
    //Now sometimes situations occur where we have to use one datamodel inside //other datamodel.
    public Student StudentModel;
    }
    

提交回复
热议问题