[Expand]General Information
[Expand]WinForms Controls
[Expand]ASP.NET Controls and MVC Extensions
[Expand]ASP.NET Bootstrap Controls
[Expand]ASP.NET Core Bootstrap Controls
[Expand]WPF Controls
[Expand]Xamarin Controls
[Expand]Windows 10 App Controls
[Expand]Office File API
[Expand]Report and Dashboard Server
[Collapse]eXpressApp Framework
 [Collapse]Getting Started
  [Expand]Basic Tutorial (SimpleProjectManager Application)
  [Collapse]Comprehensive Tutorial (MainDemo Application)
   [Collapse]Business Model Design
     Create a Solution using the Wizard
    [Expand]Business Model Design with Entity Framework
    [Collapse]Business Model Design with XPO
      Inherit from the Business Class Library Class (XPO)
      Supply Initial Data (XPO)
      Implement Custom Business Classes and Reference Properties (XPO)
      Add a Class from the Business Class Library (XPO)
      Set a Many-to-Many Relationship (XPO)
      Set a One-to-Many Relationship (XPO)
      Initialize a Property After Creating an Object (XPO)
      Implement Dependent Reference Properties (XPO)
      Implement Property Value Validation in Code (XPO)
   [Expand]Extend Functionality
   [Expand]UI Customization
   [Expand]Extra Modules
   [Expand]Security System
 [Expand]Design-Time Features
 [Expand]Task-Based Help
  Frequently Asked Questions (FAQ)
 [Expand]API Reference
[Expand]eXpress Persistent Objects
[Expand]CodeRush Classic
[Expand]Cross-Platform Core Libraries
[Expand]Tools and Utilities
 End-User Documentation
View this topic on docs.devexpress.com (Learn more)

Implement Custom Business Classes and Reference Properties (XPO)

In this lesson, you will learn how to implement business classes from scratch. For this purpose, the Department and Position business classes will be implemented. These classes will be used in the Contact class, implemented previously. You will also learn the basics of automatic user interface construction for referenced objects.


Before proceeding, take a moment to review the Inherit from the Business Class Library Class (XPO) lesson.

  • Add the following Department and Position persistent classes to the Contact.cs (Contact.vb) file.

    These new classes are persistent, as they are BaseObject class descendants.


    The DefaultProperty attribute is used in the code above. This attribute is used to specify the default property of the class. You can specify the most descriptive property of your class in the DefaultProperty attribute, and its values will be displayed in the following.

    • Detail form captions
    • The leftmost column of a List View
    • The Lookup List Views (These Views will be explained in the last step of this lesson.)

    Refer to the Data Annotations in Data Model topic for additional information.

  • Add the Department and Position properties to the Contact class. The following code demonstrates this.

    The Contact class now exposes the Position and Department reference properties.


    If you have CodeRush installed, you can use Code Templates when implementing business classes. Using Code Templates decreases code creation time, because it helps avoid having to type the entire code manually and allows you to create regular code sections with only a few keystrokes. To learn about the built-in Code Templates for eXpress Persistent Objects, refer to the XPO and XAF Templates topic.

  • Run the WinForms or ASP.NET application. You will see how the user interface is automatically generated using the specified data structures. The navigation control will contain new Department and Position items, which will allow you to access Department and Position objects. Note that in the Contact Detail View, a lookup editor has been created for Department and Position. In this editor, a special type of View, Lookup List View, is used. Typically, this View has a single column corresponding to the class' default property. Using the lookup editor, you can select the required Department (Position) for the current Contact, and add new Department (Position) objects using the New button. In addition, you will also be able to edit existing Department (Position) objects by holding down SHIFT+CTRL and clicking the selected object.

You can see the code demonstrated in this lesson in the MySolution.Module | Business Objects | Contact.cs (Contact.vb) file of the Main Demo installed with XAF. The MainDemo application is installed in %PUBLIC%\Documents\DevExpress Demos 19.1\Components\eXpressApp Framework\MainDemo by default. The ASP.NET version is available online at http://demos.devexpress.com/XAF/MainDemo/.


Next Lesson: Add a Class from the Business Class Library (XPO)

Expanded See Also

Is this topic helpful?​​​​​​​