Back to Devexpress

Implement Custom Business Classes and Reference Properties (EF 6)

expressappframework-113632-getting-started-in-depth-tutorial-winforms-webforms-business-model-design-business-model-design-with-entity-framework-6-implement-custom-business-classes-and-reference-properties-ef.md

latest2.8 KB
Original Source

Implement Custom Business Classes and Reference Properties (EF 6)

  • Jun 25, 2021
  • 3 minutes to read

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

Note

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

  • Add the Position class as shown in the Inherit from the Business Class Library Class (EF 6) lesson. Replace the auto-generated code with the following.

  • Register the new class in DbContext. Edit the BusinessObjects_MySolutionDbContext.cs_ file as shown below.

  • Add the Position property to the Contact class. The following code demonstrates this.

  • Run the WinForms or ASP.NET Web Forms application. You will see how the user interface is automatically generated using the specified data structures. The navigation control will contain a new Position item, which will allow you to access Position objects. Note that in the Contact Detail View, a lookup editor has been created for 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 Position for the current Contact , and add new Position objects using the New button. In addition, you will also be able to edit the existing Position object by holding down SHIFT + CTRL and clicking the selected object.

You can see the code demonstrated in this lesson in the EFDemo.Module | Data | Contact.cs (Contact.vb) and Position.cs (Position.vb) files of the EF Demo (Code First) installed with XAF. By default, the EF Demo (Code First) application is installed in %PUBLIC%\Documents\DevExpress Demos 21.2\Components\eXpressApp Framework\EFDemoCodeFirst.

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