Initialize Business Object Properties (EF Core)
- 2 minutes to read
This lesson explains how to initialize properties in newly created business class instances.
For this purpose, you will add the Priority property to the DemoTask class created in the Set a Many-to-Many Relationship (EF Core) lesson. Then you will initialize the new property.
Note
Before you proceed, take a moment to review the previous lessons:
Step-by-Step Instructions
Add the Priority property to the DemoTask class and declare the Priority enumeration, as shown below:
namespace MySolution.Module.BusinessObjects { //... public class DemoTask : Task { //... Priority priority; public Priority Priority { get => priority; set => SetPropertyValue(ref priority, value); } } public enum Priority { Low = 0, Normal = 1, High = 2 } }
In the Module.cs file, call the EnumProcessingHelper.RegisterEnum method to register the
Priority
enumeration type in the constructor of your ModuleBase descendant.using DevExpress.Data.Filtering; //... public sealed partial class MySolutionModule : ModuleBase { public MySolutionModule() { InitializeComponent(); EnumProcessingHelper.RegisterEnum(typeof(MySolution.Module.BusinessObjects.Priority)); //... } //... }
Use the code below to initialize the newly added
Priority
property when aDemoTask
object is created.public class DemoTask : Task { public DemoTask() : base() { //... Priority = Priority.Normal; } //... }
Run the application.
Create a new DemoTask object. In the Task detail view, the Priority property is set to
Priority.Normal
, as declared in the code above.Note that XAF generates a combo box for the Priority property. The combo box items are the enumeration values declared in step 2.
Next Lesson
Implement Dependent Reference Properties (EF Core)