[Expand]General Information
[Collapse]WinForms Controls
  .NET Core Support
 [Expand]What's Installed
 [Expand]Build an Application
 [Expand]Controls and Libraries
 [Collapse]Common Features
  [Collapse]Data Binding Common Concepts
    How to: Bind GridControl to Database and Implement Master-Detail Mode at Design Time
    How to: Bind a Control to a Database at Runtime
    How to: Bind a Control to Data Created at Runtime
    How to: Bind a Control to Data in an XML File
    Traditional Data Binding Methods
    Data Source Configuration Wizard
    Data Binding Mechanism in ADO.NET
    Binding Controls to XML Data
    Binding Controls to Data Created at Runtime
    Add Unbound Data to a Data-Aware Control (XtraGrid, XtraPivotGrid)
    Binding to Excel Data Sources
    Binding to LINQ to SQL Classes
    Unbound Sources
    Binding to Entity Framework Core
    Binding to OData
    Bind to JSON Data
    Bind to XPO Data
    Bind to Azure SQL Database
    Binding to SQL Data
    Data Annotation Attributes
    How to: Add Virtual Rows Using the UnboundSource Component
    Obtaining Fields Available in Data Source
  [Expand]Data Source Wizard
  [Expand]Application Appearance and Skin Colors
  [Expand]Filtering UI Context
   Find Panel Syntax
  [Expand]Graphics Performance and High DPI
  [Expand]Scaffolding Wizard
  [Expand]Formatting Values
   HTML-inspired Text Formatting
  [Expand]Save and Restore 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]Office File API
[Expand]Report and Dashboard Server
[Expand]eXpressApp Framework
[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)

Binding to Entity Framework Core

Entity Framework (EF) Core is a lightweight, extensible, and cross-platform version of the popular Entity Framework data access technology. To bind a DevExpress data-aware control to an EF Core source, you need to manually create a Data Model first. Then, utilize the Data Source Configuration Wizard.

Expanded Database and Data Model

Depending on the database provider you choose, you may be required to execute different steps and install different NuGet packages. Below are a few Microsoft tutorials on creating code-first Models or EF Models based on existing databases.

The example below illustrates how to generate an EF model from a sample Adventure Works 2014 database stored at the SQL Express server.

  1. Create a new WinForms solution using the DevExpress Template Gallery. Choose the "Grid based UI" template to create a Data Grid control hosted within a skinnable XtraForm.
  2. Make sure the target .NET framework of your project is version 4.5 or higher. To check and modify the target framework version, go to "Project | <Your_Project_Name> Properties", then use the "Target framework" editor to select the required version.

  3. For Entity Framework Core 2.0, perform additional steps before proceeding.

    • Make sure you have Visual Studio 2017 (version 15.3.1 and newer) installed - older VS versions are not supported.
    • Install .NET Core SDK.
    • Open Visual Studio settings ("Debug | Options"), switch to the "NuGet Package Manager | General" tab and choose "PackageReference" as the default package management format.

      Alternatively, you can add the following line to your .csproj/.vbproj file.

    • Enable automatic binding redirect generation by adding the following line to the .csproj/.vbproj file.


    See the official Microsoft Issues with .NET Standard 2.0 with .NET Framework & NuGet blogpost for the information on resolving possible issues that may occur when using EF Core 2.0.

  4. Open the PMC ("Tools | NuGet Package | Package Manager Console") and enter the following lines one-by-one to install the required packages.

    • Microsoft SQL Server database provider

      PM > 

      Install-Package Microsoft.EntityFrameworkCore.SqlServer

    • Entity Framework Core Package Manager Console Tools

      PM > 

      Install-Package Microsoft.EntityFrameworkCore.Tools


    Refer to the Database Providers article to learn how to install NuGet packages for other providers.

  5. In PMC, enter the following line to generate an EF model based on your database. Note that you must replace the connection parameters (Server, Database and login credentials) with your actual values.

    PM > 

    Scaffold-DbContext "Server=MYSERVER\SQLEXPRESS;Database=AdventureWorks2014;Trusted_Connection=True;" Microsoft.EntityFrameworkCore.SqlServer

    This will add multiple class files to your solution. The "<Database_Name>Context" class represents a session with the database and allows you to query and save instances of the entity classes. Other files represent individual database tables.

  6. Rebuild your project.

Expanded Data Binding

  1. Invoke the Data Source Configuration Wizard for the Data Grid control and select "Entity Framework (EF) Core". If the Data Model was generated correctly, you will see it under the "Data Sources" header. Select it and click "Next" to proceed.

  2. Select the required connection type.

    The last two options enable Server and Instant Feedback Mode modes. Selecting these modes will result in adding the PLinqServerModeSource or PLinqInstantFeedbackSource components respectively.

  3. Select the required database table. For all connection types except for direct binding, you can also apply sorting by the selected data field.

  4. Run the application to see the result.

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