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
- /// <Summary>
- /// User
- /// </Summary>
- [Serializable]
- [DataObject]
- [Description ("user")]
- [BindTable ("UserMember", Description = "user", ConnName = "Test")]
- Public partial class UserMember
- {
- # Region attributes
- Private Int32 _ ID;
- /// <Summary>
- /// No.
- /// </Summary>
- [Description ("no.")]
- [DataObjectField (true, true, false, 10)]
- [BindColumn ("ID", Description = "no.", DefaultValue = "", Order = 1)]
- Public Int32 ID
- {
- Get {return _ ID ;}
- Set {if (OnPropertyChange ("ID", value) _ ID = value ;}
- }
- Private String _ Account;
- /// <Summary>
- /// Account
- /// </Summary>
- [Description ("account")]
- [DataObjectField (false, false, true, 50)]
- [BindColumn ("Account", Description = "Account", DefaultValue = "", Order = 2)]
- Public String Account
- {
- Get {return _ Account ;}
- Set {if (OnPropertyChange ("Account", value) _ Account = value ;}
- }
- Private String _ DisplayName;
- /// <Summary>
- /// Display name
- /// </Summary>
- [Description ("display name")]
- [DataObjectField (false, false, true, 50)]
- [BindColumn ("DisplayName", Description = "display name", DefaultValue = "", Order = 3)]
- Public String DisplayName
- {
- Get {return _ DisplayName ;}
- Set {if (OnPropertyChange ("DisplayName", value) _ DisplayName = value ;}
- }
- # Endregion
-
- # Region get/set the field value
- /// <Summary>
- /// Obtain/set the field value.
- /// An index. The base class is implemented using reflection.
- /// The derived object class can override this index to avoid performance loss caused by reflection.
- /// </Summary>
- /// <Param name = "name"> Field name </param>
- /// <Returns> </returns>
- Public override Object this [String name]
- {
- Get
- {
- Switch (name)
- {
- Case "ID": return ID;
- Case "Account": return Account;
- Case "DisplayName": return DisplayName;
- Default: return base [name];
- }
- }
- Set
- {
- Switch (name)
- {
- Case "ID": _ ID = Convert. ToInt32 (value); break;
- Case "Account": _ Account = Convert. ToString (value); break;
- Case "DisplayName": _ DisplayName = Convert. ToString (value); break;
- Default: base [name] = value; break;
- }
- }
- }
- # Endregion
- # Region field name
- /// <Summary>
- /// Obtain the field name shortcut
- /// </Summary>
- Public class _
- {
- /// <Summary>
- /// No.
- /// </Summary>
- Public const String ID = "ID ";
- /// <Summary>
- /// Account
- /// </Summary>
- Public const String Account = "Account ";
- /// <Summary>
- /// Display name
- /// </Summary>
- Public const String DisplayName = "DisplayName ";
- }
- # Endregion
- }
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.