Log In
Home
Support
Demos
Documentation
Blogs
Training
Webinars
[Expand]General Information
[Expand]WinForms Controls
[Expand]ASP.NET Controls and MVC Extensions
[Expand]ASP.NET Bootstrap Controls
[Expand]ASP.NET Core Bootstrap Controls
[Collapse]WPF Controls
  Prerequisites
 [Expand]What's Installed
 [Expand]Common Concepts
 [Expand]MVVM Framework
 [Expand]Controls and Libraries
 [Collapse]Scaffolding Wizard
   Getting Started
  [Expand]Overview
  [Collapse]Data Access Layer
    How To: Generate Data Access Layer with Entity Framework Database First
    How To: Generate Data Access Layer with Entity Framework Code First
    How To: Generate Data Access Layer Based On Data Provided By a WCF Service
   UI Generation
  [Expand]Examples
  [Expand]Tutorials
 [Expand]Localization
  Redistribution and Deployment
  Get More Help
 [Expand]API Reference
[Expand]Xamarin Controls
[Expand]Windows 10 App Controls
[Expand]Office File API
[Expand]Reporting
[Expand]Report Server
[Expand]Dashboard
[Expand]eXpressApp Framework
[Expand]CodeRush
[Expand]CodeRush Classic
[Expand]Cross-Platform Core Libraries
[Expand]Tools and Utilities
 End-User Documentation

How To: Generate Data Access Layer with Entity Framework Code First

This topic gives a step-by-step description of how to generate the Data Access Layer based on a predefined data model with the Entity Framework.

Create an empty WPF application (you can use the Template Gallery to do this), or open an existing project and follow the steps below.

The complete sample project is available in the DevExpress Code Examples database at: http://www.devexpress.com/example=T319497.

Expanded Define Data Structure

Create a new file (for example, Model.cs(vb)) and add the following data classes to it.

Expanded Add NuGet Package

Add the Entity Framework NuGet package to your project. Right-click the project in the Solution Explorer and select the Manage NuGet Packages option.

Note

If you do not have the Manage NuGet Packages option, install the latest version of NuGet.

Input the Entity Framework text to the search box, find the EntityFramework package, click Install and accept the License Agreement.

Expanded Define a Database Context

Define a database context that represents a session with the database and allows you to query and save data.

The defined data context represents the Data Access layer in our application.

Expanded Add Sample Data

Add the DepartmentContext initializer that will seed the database with sample data when the application starts for the first time.

Then, register it on the application startup callback.

Expanded What is Next?

When, the Data Access Layer is generated, you can use our Scaffolding Wizard to generate the other parts of a database-oriented application. The UI Generation topic describes how to do this step-by-step.

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