How-To: Create Business Entities

This walkthrough will get you started on using the Inertia: Business Entity Component Generator to create business entity classes. Before beginning this guide, please make sure you have created a layered application from the solutions template or have completed the Get Started with Layered Architecture Solution Guidance walkthrough.


  1. In Solution Explorer, right-click on your Business.Entities project i.e. ExpenseSample.Business.Entities and click Add Business Entities…

    09
  2. The Inertia: Business Entity Component Generator will be launched. Take some time to familiarize with Inertia’s user interface.

    01_thumb1
  3. Click Connect to connect to a Microsoft SQL Server.

  4. In the Connect… dialog, enter your Server name and select the appropriate authentication method. Click Connect to connect the SQL server. 


    02_thumb1
  5. Select a database from the database list located beside the Connect button.

  6. In the Source tab, select a table from the Sources dropdown list. Inertia will attempt to suggest the entity class name for you based on the selected table’s name.

  7. Select the columns you wish to include in your entity from the Columns list. To select more than one column, hold the Ctrl key while clicking the column names. To select or de-select all columns at once, check the Columns checkbox.

  8. The Reference To tab shows any tables that the selected table has a reference to. The tables listed in the Referenced sources will have a primary key connected to the selected table. You can choose to relate the table as an Entity or you can select the columns which you want to include. To add the columns to the properties list, click on the + (plus) button at the bottom of the tab page.

  9. The Referenced By tab shows tables that references the selected table. These tables if selected will be created as List<T> properties in the Entity. To add them to the properties list, click on the + (plus) button at the bottom of the tab page.

  10. Click the + (plus) button to add the selected columns to the Entity properties list. You can also double-click on each column name to add them individually. You can choose any of the options listed at the bottom of the screen to apply the settings at one-go when you include the columns or you can individually set them later.


    03_thumb1
  11. Optional - In some cases, the column names may contain abbreviations, prefixes or suffixes that make them less meaningful as property names i.e. hr_WkflowID, PrdName, StdMercName etc. You can rectify this with column mappings. If you do not have such column names, skip ahead to step 14. To define column mappings, click on the bar above the column list. This will launch the Define Column Mappings dialog.


    04_thumb1
  12. Column mappings allow you to map underlying table columns to meaningful property names in your entities. You can rename your Property Names, change its case and do whatever required to make them meaningful. When you are done with the mappings, click OK.

  13. A confirmation dialog will be shown. You can choose to apply the mappings immediately by clicking Yes or click No to not apply the mappings. The mappings that you have defined will be stored on your computer for future uses.

  14. The columns you chose to include will appear in the Entity properties list. You can make any necessary configurations to the properties such as changing its Display Name and marking it with certain attributes. To remove a column from the list, select a property name and press the Delete key on your keyboard.


    05_thumb1
  15. Confirm your Entity name.

  16. Click Add to Code Generation to queue your entity definition for code generation. You can queue as many entities for code generation as you wish. To create another entity, simply click on New.

  17. Entities queued for code generation will be listed in the Business Entities to generate list and the properties will be listed in the Properties to generate list under the Code Generation section. You can review the definitions and make any last moment changes to them in the property grid below the list.

    Warning! Tampering with the properties in the property grid may cause unexpected results or errors in code generation. Make sure you understand the behavior of the code generator before messing with the values in the property grid.


    06_thumb1

    To mark existing entities for re-generation, you can click on the Reset button (double rotating arrow icon). This sets the IsUpdated property of the definition to true. You can also do this manually in the property grid. 

    To remove an entity from queue, click on the X (remove) button. This does not remove your entity code file from Visual Studio but only removes the definition.
    To remove a property definition from the list, select a property name from the Properties to generate list and press the Delete key on your keyboard. This does not remove the property from your code but only removes the definition from the list.

    Warning! Removed entity or property definitions are not recoverable.

    You can preview how the code will be generated by clicking on the preview button (Book icon).

  18. Click Generate to generate your entity classes.

  19. In the Code Generation Completed dialog, click OK.

  20. The Business Entity project will now contain the code file(s) of the generated entity classes. Review the generated code and make any necessary changes according to your needs.


    07_thumb1
  21. If you are regenerating code or if a code file exist in the project, you will be prompted to either Append, Backup, Overwrite or Cancel the process.


    08_thumb1

    Append will append whatever new properties to the bottom of the class. Take note it is not an intelligent append and duplicate properties may be appended to your class.

    Backup creates a copy of your code file with a .bak extension and requires you to manually include its contents into your project.

    Overwrite will replace your existing entity class with a newly generated one. Any previously defined properties that were not included in the latest code generation will be lost.

    Cancel will discard the generated code from memory and preserves the existing code file.

  22. Finally, right-click on the Business.Entities project and click Build to build the project to ensure no errors.


How-To: Get started with Layered Architecture Solution Guidance | How-To: Create Data Access Components

Last edited Aug 6, 2011 at 9:50 AM by firedancer, version 7

Comments

eferreyra Aug 15, 2013 at 5:23 PM 
Too bad only Sql Server is supported, i have my Entity Framework model from some Informix database, can i still use some code generator ?

sagarmakde Jan 23, 2012 at 11:41 AM 
Only Sql server connection is available?Oracle connection is not display.