Write the ORM framework by yourself (5): link ing configuration-Column attribute

Source: Internet
Author: User

This time, we will complete the last custom attribute function Column. before talking about Column implementation, let's take a look at the structure of the Student table as follows: create table student (studentid VARCHAR2 (40), studentno VARCHAR2 (40 ), name VARCHAR2 (40), address VARCHAR2 (40), telphone VARCHAR2 (40) Then let's take a look at the specific usage code of Column Custom Attributes 1-1: using System; using System. data; using System. collections. generic; using System. text; using System. orm. customAttributes; namespace Entity {[Serializable] [Table (Name = "Student")] public class StudentEntity {private string stuid; private string stuno; private string name; private int sex; private int age; private string address; private string telphone; [Id (Name = "studentid ", strategy = GenerationType. INDENTITY)] public string Stuid {get {return stuid;} set {stuid = value;} [Column (Name = "studentno")] public string Stuno {get {return stuno;} set {stuno = value ;}} public strin G Name {get {return name;} set {name = value;} [Column (IsInsert = false, IsUpdate = false)] public int Sex {get {return sex ;} set {sex = value ;}[ Column (IsInsert = false, IsUpdate = false)] public int Age {get {return age ;}set {age = value ;}} public string Address {get {return address;} set {address = value;} public string Telphone {get {return telphone;} set {telpho Ne = value ;}}}configure ing relationships on the attributes of the StudentEntity object class above. The Table and Id custom attributes have been described before, this section describes how to configure Column. [Column (Name = "studentid")] This configuration is added to the public string Stuid {get ......} The above indicates that this attribute corresponds to the studentid column in the Student table. In public string Name {get ...} The program considers that the attribute Name is the same as the Name of the column in the Student table and does not need to be mapped separately. The Gu Student table also has the Name column. [Column (IsInsert = false, IsUpdate = false)] here the value of Column Name is not set, but the value of IsInsert and IsUpdate, meaning that the attribute value does not need to be inserted into the database, we can ignore the IsInsert and IsUpdate operations without processing them. The following code shows the implementation of the Column custom attribute class: 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 columnattriple: Attribute {private string _ Name = string. empty; // name of the column private bool _ IsUnique = false; // whether the column is unique private bool _ IsNull = true; // whether the column is allowed Empty private bool _ IsInsert = true; // whether to insert it into the table private bool _ IsUpdate = true; // whether to modify it to public ColumnAttribute () in the table () {} public string Name {get {return _ Name;} set {_ Name = value ;}} public bool IsUnique {get {return _ IsUnique ;} set {_ IsUnique = value ;}} public bool IsNull {get {return _ IsNull;} set {_ IsNull = value ;}} public bool IsInsert {www.2cto.com get {return _ IsInsert;} set {_ IsInsert = value ;}} public bool IsUpdate {get {return _ IsUpdate;} set {_ IsUpdate = value ;}}} so far, the custom attributes have been completed, in the future, we will discuss how to add, delete, modify, and query Objects Based on their configurations.

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.