Skip to content
christoforosl edited this page Jun 16, 2015 · 30 revisions

Code Generation of ORM classes.

Before saving objects to the database, one ORM class per database table must exist. Each ORM class must inherit from abstract class ModeloObject. These ORM classes can be generated by the code generation tool of this project. The code generation tool downloads and installs with the Nuget package of the solution

Below are the steps invloved in generating the ORM classes:

  1. Create a .NET "Class Library" project, which will contain: (1) The XML Generation Control File and (2) All generated ORM classes

  2. Create a .NET Test Project to receive Test classes generated by the code generator.

  3. Modify your database to follow these simple conventions:

  4. All tables should have a SINGLE primary key field. If you have composite keys, you can Add a new primary key and make the composite key fields to compose a unique index.

  5. Primary Keys should be either Integer, Long or String fields.

  6. Prepare XML Generation Control File. This file tells the code generator for which tables in the database it should generate ORM classes for. A sample file can be found here: Sample XML for C# generation. The XSD file is at this URL: https://raw.githubusercontent.com/christoforosl/codegen-lib/master/org.codegen.libs/org.codegen.lib/classGenerator.4.xsd

  7. Run code generation: The Nuget package of the solution installs the Code Generation EXE file in the tools folder. Alternatively you can download the executable file from the releases folder of this Github project. To run code Generation you simply run the exe codeGenWin4.exe. At the system windowm click "Select" button and then select your XML Generation Control File you created. Then click button "Generate"


After Generation of ORM Classes, the Code Generator informs you of the New Files Generated,Modified Files, and presents a confirmation message like below:
![](https://github.com/christoforosl/codegen-lib/wiki/gene2.PNG)
  1. Run unit Tests: The next step is to run the unit tests generated and confirm that the generated ORM classes can load and save data from the database.
    The Code Generator generates one Test Class for each table that is generated. The Test class name has the prefix "TestLoadAndSave[Table Name]". Below image shows the generated classes and the unit test results run.
    Note that for tables without data, the tests are marked as Inconclusive as shown above for table "employeetype" ( Test Class TestLoadAndSaveEmployeeType )

Miscalleneous Features 1. How to Add Enumerated Values

Clone this wiki locally