Detailed description of ORM Component XCode tutorials (1)

Source: Internet
Author: User

The XCode tutorial of the orm Component is the content to be introduced in this article. This is the first article in The XCode tutorial. The speed view aims to attract developers with the shortest length of the most concise language. The introduction is an overall introduction to XCode components and XCode development models, let developers understand XCode from a macro perspective; dancing brings XCode to a new height and allows developers to feel its aristocratic lineage!

Three articles are first thrown out to attract people, and then "hands-on" is actually an appetite. If you haven't tried XCode yet, I admit it's my failure, but you can cheat me, don't cheat yourself!

In XCode development mode, we recommend that you have a database and an entity model first, and then use the code generator to generate entity code. Of course, you can also create an entity model first. Entities under XCode support reverse generation of database structures.

The following uses UserMember in quick view as an example to create a data table:

Data Table Name: UserMember)

 

Database naming rules:

1) names must be spelled out in plain English words, except for commonly used acronyms such as ID.

2) use the camper naming rules. Each word has an upper-case letter and other lower-case letters.

3) The name must be concise and clear. Do not add additional prefixes such as tbl before the table name. Do not add the table name prefix for the field name.

4) the SQL keyword or C # keyword cannot be used as the table name or field name.

5) The Boolean field name must be in the IsAbb format.

6) nvarchar is used for all string types, and ntext is used for large text types. Unless otherwise specified, no other text types are used.

7) we recommend that you create an auto-increment ID field for each table and use it as the primary key to facilitate data paging management.

8) we recommend that you add instructions to each table and each field.

9) use the code generator to generate the code first. The process will be discussed later ):

Code

 
 
  1. /// <Summary>
  2. /// User
  3. /// </Summary>
  4. [Serializable]
  5. [DataObject]
  6. [Description ("user")]
  7. [BindTable ("UserMember", Description = "user", ConnName = "Test")]
  8. Public partial class UserMember
  9. {
  10. # Region attributes
  11. Private Int32 _ ID;
  12. /// <Summary>
  13. /// No.
  14. /// </Summary>
  15. [Description ("no.")]
  16. [DataObjectField (true, true, false, 10)]
  17. [BindColumn ("ID", Description = "no.", DefaultValue = "", Order = 1)]
  18. Public Int32 ID
  19. {
  20. Get {return _ ID ;}
  21. Set {if (OnPropertyChange ("ID", value) _ ID = value ;}
  22. }
  23. Private String _ Account;
  24. /// <Summary>
  25. /// Account
  26. /// </Summary>
  27. [Description ("account")]
  28. [DataObjectField (false, false, true, 50)]
  29. [BindColumn ("Account", Description = "Account", DefaultValue = "", Order = 2)]
  30. Public String Account
  31. {
  32. Get {return _ Account ;}
  33. Set {if (OnPropertyChange ("Account", value) _ Account = value ;}
  34. }
  35. Private String _ DisplayName;
  36. /// <Summary>
  37. /// Display name
  38. /// </Summary>
  39. [Description ("display name")]
  40. [DataObjectField (false, false, true, 50)]
  41. [BindColumn ("DisplayName", Description = "display name", DefaultValue = "", Order = 3)]
  42. Public String DisplayName
  43. {
  44. Get {return _ DisplayName ;}
  45. Set {if (OnPropertyChange ("DisplayName", value) _ DisplayName = value ;}
  46. }
  47. # Endregion
  48.  
  49. # Region get/set the field value
  50. /// <Summary>
  51. /// Obtain/set the field value.
  52. /// An index. The base class is implemented using reflection.
  53. /// The derived object class can override this index to avoid performance loss caused by reflection.
  54. /// </Summary>
  55. /// <Param name = "name"> Field name </param>
  56. /// <Returns> </returns>
  57. Public override Object this [String name]
  58. {
  59. Get
  60. {
  61. Switch (name)
  62. {
  63. Case "ID": return ID;
  64. Case "Account": return Account;
  65. Case "DisplayName": return DisplayName;
  66. Default: return base [name];
  67. }
  68. }
  69. Set
  70. {
  71. Switch (name)
  72. {
  73. Case "ID": _ ID = Convert. ToInt32 (value); break;
  74. Case "Account": _ Account = Convert. ToString (value); break;
  75. Case "DisplayName": _ DisplayName = Convert. ToString (value); break;
  76. Default: base [name] = value; break;
  77. }
  78. }
  79. }
  80. # Endregion
  81. # Region field name
  82. /// <Summary>
  83. /// Obtain the field name shortcut
  84. /// </Summary>
  85. Public class _
  86. {
  87. /// <Summary>
  88. /// No.
  89. /// </Summary>
  90. Public const String ID = "ID ";
  91. /// <Summary>
  92. /// Account
  93. /// </Summary>
  94. Public const String Account = "Account ";
  95. /// <Summary>
  96. /// Display name
  97. /// </Summary>
  98. Public const String DisplayName = "DisplayName ";
  99. }
  100. # Endregion
  101. }

There are not many codes, which are divided into attributes, indexers, and Nested classes. The last two are not necessary, so manual encoding is not too troublesome.

The Code Generator XCoder used is an XCode-based template tag replacement generator. XCode provides database structure information, user design templates, and XCoder is replaced by template tags. The code above also contains data dictionary tables generated by XCoder, but the templates used are different. If you are interested, you can customize your own code generator. The Tables attribute of the DAL class can obtain the table schema information of the connection, such as DAL. create ("Test "). tables can obtain the Architecture Information of the database with the connection name Test.


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.