When talking about Model design, let's talk about its role:
Model is also called an object class. A Class in the model layer corresponds to a table in the database, and each attribute in the class corresponds to a field in the table, each attribute has its own GET and SET methods. Data access in the project depends on GET and SET methods. specifically, it does not belong to any vertical layer, but to the business entity layer that all layers need to use. In fact, the main function is to pass parameters.
The following describes how to create a Model class in four ways:
Method 1:
Create department entity class department. cs:
View sourceprint? Public class department
{
Private int _ id;
Private string _ partition name;
Private string _ description;
Public int id
{
Set {_ id = value ;}
Get {return _ id ;}
}
Public string CommonName
{
Set {_ partition name = value ;}
Get {return _ response name ;}
}
Public string description
{
Set {_ description = value ;}
Get {return _ description ;}
}
}
Create M's M. cs:
View sourceprint? Public class custom
{
Private int _ id;
Private string _ cname;
Private string _ ename;
Private int _ departID;
Private int _ age;
Private string _ password;
Private string _ partition name;
Public string CommonName
{
Set {_ partition name = value ;}
Get {return _ response name ;}
}
Public int id
{
Set {_ id = value ;}
Get {return _ id ;}
}
Public string cname
{
Set {_ cname = value ;}
Get {return _ cname ;}
}
Public string ename
{
Set {_ ename = value ;}
Get {return _ ename ;}
}
Public int departID
{
Set {_ departID = value ;}
Get {return _ departID ;}
}
Public int age
{
Set {_ age = value ;}
Get {return _ age ;}
}
Public string password
{
Set {_ password = value ;}
Get {return _ password ;}
}
}
We have built the entity class. In fact, there is also a simpler method, with the same effect as above:
Method 2:
Department. cs
View sourceprint? Public class department
{
Public int id
{
Set;
Get;
}
Public string CommonName
{
Set;
Get;
}
Public string description
{
Set;
Get;
}
}
Custom. cs:
View sourceprint? Public class custom
{
Public string CommonName
{
Set;
Get;
}
Public int id
{
Set;
Get;
}
Public string cname
{
Set;
Get;
}
Public string ename
{
Set;
Get;
}
Public int departID
{
Set;
Get;
}
Public int age
{
Set;
Get;
}
Public string password
{
Set;
Get;
}
}
You can also create an instance using the following method:
Method 3:
Custom. cs:
View sourceprint? Public class custom
{
Private int _ id;
Private string _ cname;
Private string _ ename;
Private int _ departID;
Private int _ age;
Private string _ password;
Private string _ partition name;
Public string CommonName
{
Get {return _ response name ;}
}
Public int id
{
Get {return _ id ;}
}
P