Initialize Entity Properties
- 2 minutes to read
This lesson explains how to initialize properties in the newly created entity instances.
The steps below show how to add a Priority property to the DemoTask class and how to initialize the property value. For DemoTask class implementation code, see the following lesson: Set a Many-to-Many Relationship.
Note
Before you proceed, take a moment to review the previous lessons:
Step-by-Step Instructions
Add the
Priorityproperty to theDemoTaskclass and declare thePriorityenumeration:namespace MySolution.Module.BusinessObjects { //... public class DemoTask : BaseObject { //... public virtual Priority Priority { get; set; } } public enum Priority { Low = 0, Normal = 1, High = 2 } }Use the code below to initialize the newly added
Priorityproperty when you create aDemoTaskobject:public class DemoTask : BaseObject { //.. public override void OnCreated() { Priority = Priority.Normal; } //... }Run the application.
Create a new
Taskobject. In the Task detail view, thePriorityfield value isNormal, as you declared in the code above.- ASP.NET Core Blazor

- Windows Forms

Note that XAF generates a combo box for the
Priorityproperty. The combo box items are the enumeration values you declared in step 1.- ASP.NET Core Blazor

- Windows Forms

Next Lesson
Implement Dependent Reference Properties