Introduction to MVC Architecture-serialization attribute and mvc Architecture serialization attribute

Source: Internet
Author: User

Introduction to MVC Architecture-serialization attribute and mvc Architecture serialization attribute

 Instance product based on asp.net mvc 5.0 framework, source code: http://www.jinhusns.com/Products/Download

During design, if we can predict that some entities may add some attributes in subsequent R & D (or secondary development), in order to quickly increase or decrease these attributes, provides a design mechanism for serializable attributes. Serializable attributes have the following features:

Advantages:
The serializable attributes of an object are serialized and stored in the database. Therefore, you do not need to change the database design to add or subtract serializable attributes;
Disadvantages:
Only simple data types are supported, such as string, bool, int, and datetime;
Because serializable attributes are stored in the database after being serialized in a unified manner, you cannot use serializable attributes as query conditions or sorting conditions through SQL statements.

 

Add the PropertyNames and PropertyValues fields to the database table corresponding to the object (set as an empty field );

Usage:
1. derive your own entity class from SerializablePropertiesBase and add the Serializable annotation;
2. serializable attributes. Because the storage of the corresponding database table is not required, you must add [Ignore] (orm annotation to prevent ing). The call time is the same as that of a common attribute;

 

 

SerializablePropertiesBase is the base class of our serializable attributes, which is subject to our serialization.

 

Implementation principle:
PropertyNames = EnableRatings: S: 0: 4: EnableTrackBacks: S: 4: 4: CommentModerationType: S: 8: 4:
PropertyValues = TrueTrueNone
"S: 0: 4" indicates that the four-character substring in the PropertyValues field starting from the position 0 belongs to the attribute value of "EnableRatings", similarly: "S: 4: 4 "indicates that the four-character substring starting from position 4 belongs to the attribute value of" EnableTrackBacks ", and the values of all PropertyNames fields can be obtained in turn. (S indicates that the storage format is string, so you do not need to pay special attention to it because all are currently stored as strings ). Therefore, the value of EnableRatings can be parsed to True.

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.