[Expand]General Information
[Expand]WinForms Controls
[Expand]ASP.NET Controls and MVC Extensions
[Expand]ASP.NET Bootstrap Controls
[Expand]ASP.NET Core Bootstrap Controls
[Expand]WPF Controls
[Expand]Xamarin Controls
[Expand]Windows 10 App Controls
[Expand]Office File API
[Expand]Report and Dashboard Server
[Collapse]eXpressApp Framework
 [Expand]Getting Started
 [Expand]Design-Time Features
 [Collapse]Task-Based Help
  [Collapse]Business Model Design
   [Expand]Common Tasks
   [Collapse]Entity Framework (EF)
     How to: Apply Attributes to Entity Properties when Using Model First
     How to: Initialize Business Objects with Default Property Values in Entity Framework
     How to: Supply Initial Data for the Entity Framework Data Model
     How to: Use the Entity Framework Code First in XAF
     How to: Use the Entity Framework Data Model Located in an External Assembly
     How to: Use the Entity Framework Model First in XAF
   [Expand]eXpress Persistent Objects (XPO)
   [Expand]Non-Persistent Objects
  [Expand]Application Model
  [Expand]List Editors
  [Expand]Property Editors
  [Expand]Scheduler and Notifications
  [Expand]Maps Module
  [Expand]Miscellaneous UI Customizations
  Frequently Asked Questions (FAQ)
 [Expand]API Reference
[Expand]eXpress Persistent Objects
[Expand]CodeRush Classic
[Expand]Cross-Platform Core Libraries
[Expand]Tools and Utilities
 End-User Documentation
View this topic on docs.devexpress.com (Learn more)

How to: Use the Entity Framework Model First in XAF

This topic demonstrates how to use the Model First entity model and a System.Data.Entity.DbContext entity container in an XAF application.

Expanded 1. Add the Entity Data Model

In the Solution Explorer, right-click the MySolution.Module\BusinessObjects folder and create a model as described in the Create Model section of the Model First topic. Specify MySolutionModel as the new file's name. Design a data model that includes the Employee and Task entities, and generate a database from this model. The image below demonstrates the model that will be used in this example.


  • In this topic, the Entity Framework Designer is not described in detail. For information on using the Entity Framework Designer, refer to the following MSDN article: Model First.
  • You can use the Generate from database feature of the Entity Data Model Wizard to reverse engineer an existing database instead of designing a data model manually.

Expanded 2. Apply Attributes to Entity Classes

XAF automatically collects entities declared in modules, and adds them to the Application Model when the DevExpress.ExpressApp.EF.v19.1.dll or DevExpress.ExpressApp.EF.45.v19.1.dll assembly is referenced. In the Model Editor, you can see List and Detail View nodes created for the Employee and Task objects. You can create navigation items to access these objects in the UI (see Add an Item to the Navigation Control).


Currently, the metadata information on EF classes and their properties is not propagated to the Model Editor at design time. As a result, tools like Filter Builder cannot display object structure. The workaround is provided in the EF - Display data model properties in the design time Model Editor ticket. We will consider supporting this scenario in future XAF versions.

However, you may want to customize the UI in code by applying XAF built-in attributes such as DefaultClassOptionsAttribute or ImageNameAttribute. In order to apply attributes to designed entity classes, you must first declare the partial Employee and Task classes that will supplement the designer-generated declarations. Once you have declared these classes, you can apply the required attributes.

To apply attributes to the Employee and Task object properties (e.g., apply the Browsable(false) attribute to the Id properties to hide the key values in the UI), utilize the approach demonstrated in the How to: Apply Attributes to Entity Properties when Using Model First topic.

Expanded 3. Run the Application

You can now run both WinForms and ASP.NET applications. The UI for each platform is automatically generated for your data model.




To learn how to fill the database with predefined data, refer to the How to: Supply Initial Data for the Entity Framework Data Model topic.

Expanded See Also

Is this topic helpful?​​​​​​​