How-To: Create Entities with Inertia in LASG

This walk-through will get you started with the Inertia: Business Entity Component Generator that is available in Layered Architecture Solution Guidance 2013. The first step in creating layered applications after designing the database is to create the entity classes. Before beginning this guide, please make sure that you have completed the previous tutorial on Getting Started with LASG.

This walk-through also uses the LeaveSample database that is part of the Layered Architecture Sample for .NET but you may use your own database to follow through.


  1. In Solution Explorer, expand the Tutorial solution, go to the Shared folder, right-click on the Tutorial.Entities project and click Add Entities...

  2. The Inertia: Business Entity Component Generator will launch. The code generator is divided into 3 sections.


    Tip: Notice the code generator is colour coded to the code generation guide.
  3. At the  1. Choose Data Source and Columns  section, click the Connect button to connect to a Microsoft SQL Server.
  4. In the Connect... dialog, enter the Server name and select the appropriate authentication method. Click Connect to connect to the SQL server.


    Note: LASG uses the SQL Server Management Objects and therefore, only Microsoft SQL Server is supported. You can use any editions of SQL Server including the Express edition.
  5. Select the LeaveSample database from the database list located beside the Connect button.
  6. In the Source tab, select the Leaves table from the Sources dropdown list. All its columns will be listed in the list box below the Columns check box.

    Tip: Inertia will attempt to suggest the entity class name for you based on the selected table’s name. If your tables have plural names, the Singularize class names option will attempt to suggest singular entity class names for you.
  7. If you are not using the LeaveSample database tables and have abbreviated column names i.e. hr_wkflowID, PrdName, StdMercName etc., you can create meaningful property names for them by clicking on the bar above the column list. This launches the Define Column Mappings dialog. Make any necessary changes to the Property Name and click OK when done.


    Note: It is recommended that you have well defined meaningful column names in the tables than to rely on the column mappings. 
  8. Check on the Columns check box to select all the columns and click on the     button to add them to the  2. Define Entity Settings  section.


    Tip: You can also individually select or deselect columns. Press the Ctrl key while clicking on the columns to select/deselect individual columns or use the Shift key to select/deselect a range of adjacent columns.

    Note: Not all data-types are supported. Complex data-types are currently not supported.
  9. The Reference To tab will show all the tables that the current table is referencing to with a foreign key. You can choose to relate to the entire table as a reference object or individually select the columns which you want to include as part of the current entity (a.k.a. borrowed columns). Once you are done with your selections, click on the    button to add them to the Entity properties grid. For simplicity, we shall not add anything from here in this tutorial.
  10. The Reference By tab shows all the tables that is referencing the current table with a foreign key. You can choose to relate the tables here as a collection of Entities. Click on the   button to add them to the Entity properties grid. You will also need to generate the Entity classes individually for the tables you selected here later. For simplicity, we shall not add anything from here in this tutorial.
  11. The columns that you choose will appear in the Entity properties grid under the  2. Define Entity Settings  section as properties to be generated for the Entity. You can make adjustments here i.e. changing the comments or marking a property to accept nulls.

    Tip: In case you want to remove any columns from the properties list, just select the row and press the Delete key on the keyboard or your can right-click on the selected row to invoke a context menu to delete it.
  12. Once you are ready, click on the Add to Code Generation button to queue the definition to the  3. Generate Entities  section. You can queue as many entities for code generation as you wish. To create another entity, simply click on the New button. For this tutorial, we shall create 2 entities - Leave and LeaveStatusLog.
  13. Each queued entity definition will be listed in the  3. Generate Entities  section. You can review the definitions and make any last moment changes in the property grid located at the bottom of the section. You can delete any entity properties by selecting the row and pressing the Delete key.


    Caution! Tampering with the properties in the property grid may cause unexpected results or errors in code generation. Make sure you understand the behaviour of the code generator before messing with the values in the property grid.
  14. You can perform various action from the tool-bar at the  3. Generate Entities  section. You can Preview the code that will be generated, set Options, reposition the properties, Reset the definitions so that they will be code-generated again or Delete the definitions.

    Warning! Deleted definitions will not be recoverable.

    Note: All definitions will be marked as code generated (indicated by the IsUpdated property) after code generation. They will continue to appear in the list but will not be code generated the next time. Clicking Reset will change one or more definitions' IsUpdated value to true and mark them for code generation again.

    You can also Delete an entity property, an entity definition or all entity definitions from the tool-bar. Clicking on the Options icon will open the Code Generation Options dialog that will allow you to set a few standard options. Leave the settings alone and click OK.

  15. Finally, click the Generate button to generate the entity classes.
  16. At the Code Generation Completed dialog, click OK.
  17. The Tutorial.Entities project should contain the generated code files for the entities.

Summary

We have basically gone through how to use the Inertia: Business Entity Component Generator to create Entity classes for our layered application. You can make any necessary changes to the code but take note that any changes made in your code will not be reflected in the definitions stored in Inertia. Therefore, practice caution when you are regenerating code on existing code file.

Coming up next - How-To: Create Data Access Components with Momentum in LASG.

No comments:

Post a Comment

Popular Post