expressappframework-402981-getting-started-in-depth-tutorial-blazor-define-data-model-and-set-initial-data-define-data-model-and-set-initial-data-with-ef-core-implement-a-data-model-basics.md
This lesson explains how to implement entity classes for your application and describes the basics of automatic user interface construction based on data.
During this lesson, you will do the following:
Entity classes do not depend on the application UI. Implement them in a platform-independent module project. This way, other XAF or non-XAF applications can share entities.
Inherit your entity classes from the base persistent class BaseObject. The BaseObject class implements the IXafEntityObject and IObjectSpaceLink interfaces. This means that CRUD operations for the declared objects are available automatically and you don’t need to implement them in your code.
For additional information on these concepts, refer to the following topic: Views.
Expand the MySolution.Module project and right-click the Business Objects folder. Choose Add | Class…. Specify Employee.cs as the new class name and click Add. Replace the auto-generated code with the following class declaration:
Go to the MySolution.Module\BusinessObjects\MySolutionDbContext file and add the following property to the MySolutionEFCoreDbContext entity container class:
Your application now contains data objects. This means that the application requires a database. You have the following options to choose from:
Use a DBMS to maintain the database (default option)
Use an in-memory database
Run the application. You can see that the UI did not change. To make the Employee item visible in the application’s navigation control, add the DefaultClassOptionsAttribute attribute to the corresponding class:
Run the application. XAF generates a user interface that is based on the specified data structures. The List View displays the collection of objects of the Employee class. Since there are no objects of this type, the Employee List View is empty for now:
Click the New button to invoke the Detail View for a new object of the Employee type. XAF renders the properties of the entity class as data fields. The Detail View contains editors for each data field.
See Also
Business Classes vs Database Tables