Ways to Add a Business Class

When designing a business model, you have to implement a number of business classes. Since many entities are common to various business applications, the eXpressApp Framework supplies a built-in Business Class Library with frequently-used business classes. You can use these classes as is or extend them. In most cases, this will still be insufficient and you will need to add custom classes. This topic describes how to do this.

Code First

  • Implement a Business Class from Scratch

    Since theeXpressApp Framework uses the eXpressPersistent Objects library (XPO) as an Object-Relational Mapping system, business classes must meet this system's requirements. For details on the basic requirements, refer to the Business Classes vs Database Tables topic. To see an example of a business class implementation, refer to the Implement Custom Business Classes and Reference Properties (XPO) lesson in the Tutorial.

  • Add Classes From a Business Class Library or Module

    The DevExpress.Persistent.BaseImpl.v18.2.dll assembly that contains the XAF Business Class Library's ready-to-use classes is added to each application module of an XAF solution. To add a class from this library to the process of automatic UI generation, declare this class as a class to be loaded to the Application Model. You can do this in any of your solution's modules. To choose the appropriate application module, determine whether this class is targeted for the Windows Forms, ASP.NET Web and Mobile applications, or just one of them.

    To load a class from the XAF Business Class Library to the Application Model, use a module's Module Designer. In the Exported Types section, select the required class represented by a child node of the Referenced Assemblies | DevExpress.Persistent.BaseImpl.v18.2.dll node. Press the SPACEBAR, or right-click and select the Use type in application context menu item. The node will be marked in bold. To cancel, repeat the same action.

    Note

    Do not forget to rebuild your solution after making changes in the Module Designer. Otherwise, you will not see them in the Model Editor.

    To see an example of a Business Class Library class usage, refer to the Add a Class from the Business Class Library (XPO) lesson in the Tutorial.

  • Add Classes from a Custom Library

    You can use classes from a custom Business Class Library or module. For this purpose, first reference the required assembly in a module. Then, use one of the following techniques:

    • Add Classes using the Module Designer

      All assemblies (no matter whether they represent a module) that contain business classes are listed in the Referenced Assemblies node of the Designer's Exported Types section. You can add a class to the UI construction process as detailed above, for classes from the XAF library.

      Note

      If a module is added to the Designer's Required Modules section, its business classes are added to the UI construction process automatically. You cannot cancel loading them to the Application Model.

      To add all the classes from an assembly, select it and press the SPACEBAR.

    • Add All Classes from an Assembly in Code

      Add the required classes to the ModuleBase.AdditionalExportedTypes collection in your ModuleBase class descendant's constructor.

      using DevExpress.ExpressApp;
      //...
      public sealed class MySolutionModule : ModuleBase {
          public MySolutionModule() {
              //...
              AdditionalExportedTypes.AddRange(
                  ModuleHelper.CollectExportedTypesFromAssembly(
                  typeof(MyNamespace.MyModule).Assembly));
          }
      }
      
    • Add a Certain Class from an Assembly in Code.

      Add the required classes to the ModuleBase.AdditionalExportedTypes collection in your ModuleBase class descendant's constructor.

      using DevExpress.ExpressApp;
      using DevExpress.Persistent.BaseImpl;
      //...
      public sealed class MySolutionModule : ModuleBase {
          public MySolutionModule() {
              //...
              AdditionalExportedTypes.AddRange(
                  new Type[] { typeof(Address), typeof(Note) });
          }
      }
      
    Note

    When you add a class to the Application Model, all the referenced classes are added as well.

    Modify a Class from a Business Class Library or Module

    To modify a class from a Business Class Library or module, inherit from it. For this purpose, use one of the following approaches.

    • Right-click the MySolution.Module project, and choose Add DevExpress Item | New Item... to invoke Template Gallery. Then select the XAF Business Object | XPO Business Object template and press Add Item. As a result, you will get an automatically generated code file with a class declaration. Change the base class that is generated to the required class by default. To see an example, refer to the Inherit from the Business Class Library Class (XPO) lesson from the Tutorial.
    • Recompile the XAF Business Class Library. For details, refer to the How to: Recompile the Business Class Library topic.
    • Modify the information on a class loaded to the Application Model. For this purpose, invoke the Model Editor and navigate to the appropriate BOModel | <Class> node.

Model First

With the XPO Data Model Designer, start your application development from building the data model within a visual designer, and get the code of underlying business classes automatically. Refer to the How to: Create a Business Model in the XPO Data Model Designer topic to get step-by-step instructions.

Database First

If you have a database with a set of tables, you can automatically generate business classes corresponding to these tables. The properties of classes will correspond to the table columns. Refer to the How to: Generate XPO Business Classes for Existing Data Tables topic for details.

See Also