Log In
Home
Support
Demos
Documentation
Blogs
Training
Webinars
[Expand]General Information
[Collapse]WinForms Controls
  Prerequisites
 [Expand]What's Installed
 [Expand]Build an Application
 [Expand]Controls and Libraries
 [Collapse]Common Features
  [Expand]Data Binding Common Concepts
  [Expand]Data Source Wizard
  [Expand]Expressions
  [Expand]Behaviors
  [Expand]Application Appearance
  [Expand]Filtering UI Context
  [Expand]High DPI Support
  [Collapse]Scaffolding Wizard
   [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
   [Expand]Generating an Application
  [Expand]Formatting Values
   HTML Text Formatting
  [Expand]Menus
  [Expand]Tooltip Management
  [Expand]Saving and Restoring Layouts
   Clipboard - Copy and Paste Operations. Data Formatting
   Version Compatibility: Default Property Values
  Get More Help
 [Expand]API Reference
[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]Document Server
[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 Database First

This tutorial will guide you through the process of creating a database-first Data Access Layer. This layer will later be used by the Scaffolding Wizard to generate an application.

  1. In Visual Studio, go to "File | New | Project" or press CTRL+SHIFT+N to create a new project. Select the DevExpress Template Gallery option and choose the "Blank Application" template.

  2. Select your project in the VS Solution Explorer window and press CTRL+SHIFT+A to add a new item. Search for the ADO.NET Entity Data Model item, then click "Add" to proceed.

  3. After the ADO.NET Entity Data Model component is added, it will automatically pop up its Data Model Wizard. On the first Wizard page, select the "Generate from Database" option and click next.

  4. Click the "New Connection..." button to add a new data connection. Next, select a database file from a local storage. Sample "Northwind" SQL Server database files for this tutorial can be found here.

  5. The final wizard page shows all tables and views found in the selected database. Tick those of them that should be added to the EF model and click "Finish".

    At this step, your Visual Studio may throw warnings, telling you that selected data base views contain multiple primary keys and thus are added to the EF model as read-only views. The Scaffolding Wizard treats database views as read-only data sets in any case, so simply ignore these warnings. Optionally, re-start Visual Studio: all warnings will be gone.

  6. If you chose to add a database file to a project, the database is copied to the output directory each time the project is rebuilt. That is, changes made to data are discarded after each rebuilding. If you wish to keep these changes, select the database in the Solution Explorer window and set its Copy to Output Directory property to Copy if newer. This way, the database is only replaced when scheme conflicts are detected.

Expanded What's Next?

Congratulations, you have created a sample Data Access Layer with a code-first Entity Framework! Check out other Data Access Layer tutorials or proceed to generating an application based on this layer.

How would you rate this topic?​​​​​​​