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.