In the previous article, the Table custom attribute function is completed, and now the Id is completed, because the most important structure of a Table is the Table name, primary key (Id), Column), primary key generation policy. Code Block 1-1: [Table (name = "Student")] public class StudentEntity {private string stuid; [Id (Name = "studentid ", strategy = GenerationType. SEQUENCE)] public string Stuid {get {return stuid;} set {stuid = value ;}} on the Stuid attribute, [Id] indicates that it is in the StudentEntity entity class, the Stuid attribute field corresponds to the primary key ID in the Student table. Name = "studentid" indicates that this attribute corresponds to the studentid column Name in the Student table. If the Name value is not specified or is empty, by default, Stuid is the same as the column name in the corresponding Student table. Strategy = GenerationType. SEQUENCE indicates the primary key generation method, which is automatically increased. The complete code block of the custom property Id is 1-2: using System; using System. collections. generic; using System. text; namespace System. orm. customAttributes {[AttributeUsage (AttributeTargets. field | AttributeTargets. property, AllowMultiple = false, Inherited = false)] public class idattriple: Attribute {private string _ Name = string. empty; private int _ Strategy = GenerationType. INDENTITY; public string Name {get {return _ Name;} Set {_ Name = value ;}} public int Strategy {get {return _ Strategy;} set {_ Strategy = value ;}}} attribute configuration on the IdAttribute class: [AttributeUsage (AttributeTargets. field | AttributeTargets. property, AllowMultiple = false, Inherited = false)] Here, AllowMultiple and Inherited write the orm framework by themselves (3): link ing configuration-Table attributes, this is not a big deal. AttributeTargets. field indicates that the Id attribute can be configured on the private member Field. Code Block 1-3: [Table (name = "Student")] public class StudentEntity {[Id (Name = "studentid ", strategy = GenerationType. SEQUENCE)] private string stuid; // [Id (Name = "studentid", Strategy = GenerationType. SEQUENCE)] public string Stuid {get {return stuid;} set {stuid = value ;}} here we add [Id] to private string stuid; above, it is the same as the property. AttributeTargets. property indicates that the Id Property can be configured on the Property. Note the part/[Id] On Stuid in 1-3. attributeTargets. field | AttributeTargets. add | in the middle of the Property to indicate or, that is, you can configure the Field or Property. A GenerationType class is also used here, with the same effect as enumeration. The source code is as follows: using System; using System. collections. generic; using System. text; namespace System. orm. customAttributes {www.2cto.com public class GenerationType {public const int INDENTITY = 1; // automatically increases public const int SEQUENCE = 2; // SEQUENCE public const int TABLE = 3; // TABLE private GenerationType () {}// private constructor. The object cannot be instantiated}. Now, the Id custom attribute is complete.