Back to Devexpress

How to: Use the Entity Framework Core Data Model Located in an External Assembly

expressappframework-403000-business-model-design-orm-business-model-design-with-entity-framework-core-how-to-use-the-entity-framework-core-data-model-located-in-an-external-assembly.md

latest2.2 KB
Original Source

How to: Use the Entity Framework Core Data Model Located in an External Assembly

  • Nov 27, 2025
  • 2 minutes to read

If you have a non-XAF application, and want to develop an XAF application that utilizes the same database, you can generate business classes for an existing database to achieve this task (see Reverse Engineering). However, if your existing application is based on the Entity Framework Core data model, you can reuse this model in XAF to avoid code duplication. This topic describes how to use the data model located within an external assembly.

Note

If the external assembly is an XAF Module, then you do not need to follow this topic. Entities declared within XAF modules are automatically recognized and added to the Application Model.

  1. Create a new XAF solution using the DevExpress Template Kit. In the ORM section, select EF Core.

  2. Reference the external assembly that contains the Entity Framework Core data model to be used.

  3. A DbContext class is required to use entities from the external assembly. To declare it, do one of the following.

  4. Open the MySolution.Module_Module.cs_ file and add the required entity types to the ModuleBase.AdditionalExportedTypes collection in the module’s constructor:

  5. Rebuild your solution, so that the changes made in the Module are loaded to the Application Model, and run the Model Editor. Make sure that the entities added in the previous step are available in the BOModel node.

  6. Add navigation items for the added entities by following the steps described in the Add an Item to the Navigation Control tutorial.

  7. Configure your application to use the correct DbContext type.