Skip to main content
A newer version of this page is available. .
All docs
V21.1
.NET Framework 4.5.2+

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

  1. 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
        }
    }
    
  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));
            //...
        }
        //...
    }
    
  3. Use the code below to initialize the newly added Priority property when a DemoTask object is created.

    public class DemoTask : Task {
        public DemoTask() : base() {
            //...
            Priority = Priority.Normal; 
        }
        //...
    }
    
  4. 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.

    xaf ASP.NET Core Blazor nitialize property value

    Note that XAF generates a combo box for the Priority property. The combo box items are the enumeration values declared in step 2.

    blazor combobox for enum

Next Lesson

Implement Dependent Reference Properties (EF Core)

See Also