If many running errors/exceptions can be checked during compilation, the potential risks in the program will be greatly reduced. This is a problem we often pay attention to when writing programs.
Using DataEntrance to use XCodeFactory is very convenient. For example, to obtain the name of a student with an ID of 200308160033, this is usually done as follows:
String name = DataEntrance. GetFieldValue (typeof (Student), "200308160033", "Name"). ToString ();
The third parameter of GetFieldValue is the field name. If the field is renamed or deleted due to business needs, the code above will still be compiled, this error is detected only when an exception is thrown during running. This leaves too many potential risks for the program, because our business often changes, and the fields in our database tables also change frequently.
I hope that the field can be deleted or modified during compilation, but cannot be compiled. What should I do? In this way, a corresponding const string field is generated for each field when the data object class is generated. The value of this field is the name of the corresponding field. For example:
Public const string _ Name = "Name ";
The third parameter of GetFieldValue is the field name. If the field is renamed or deleted due to business needs, the code above will still be compiled, this error is detected only when an exception is thrown during running. This leaves too many potential risks for the program, because our business often changes, and the fields in our database tables also change frequently.
I hope that the field can be deleted or modified during compilation, but cannot be compiled. What should I do? In this way, a corresponding const string field is generated for each field when the data object class is generated. The value of this field is the name of the corresponding field. For example:
Public const string _ Name = "Name ";
The preceding call can be changed:
String name = DataEntrance. GetFieldValue (typeof (Student), "200308160033", Student. _ Name). ToString ();
In this way, if the Name field is deleted or modified, this error can be found during compilation. Are there any better solutions? Welcome to your discussion.