Step by step. NET three-layer architecture analysis 4. Model Design (four design methods)

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.