Entity Framework , With .NET WPF, Database-First

This article is about Entity Framework with .Net WPF, Database-First approach. We will make a sample app step by step,

  • Step 1: Create an ASP.NET WPF application

  • Step 2: Reverse Engineer Model

  • Step 2-1, Alternative Approach: Code First

  • Step 3: Data Binding

  • Step 4: CURD

At the end, we will have an .Net WPF app that can consume a database directly through entity framework.

Step 1 - Create an ASP.NET WPF app

We use the current version of Visual Studio 2019 16.9.3 and .NET Framework 4.8 to build the app:

  • Start Visual Studio and select Create a new project.

  • In the Create a new project dialog, select WPF App (.NET Framework) > Next.

  • In the Configure your new project dialog, enter WPF_DatabaseFirst for Project name > Create.

Build and run the app, it will be an empty window.

Step 2, Reverse Engineer Model

For this step, whatever WPF or Web app (MVC or Web API or Web Forms), they are all the exactly same. We will skip the procedure and use the result at Step 2, from Article Entity Framework (2), with .Net MVC, Database-First,

Once the reverse engineer process completes the new model is added to the project and opened up for viewing in the Entity Framework Designer:

The created entity class, the entity context and the connection string will be exactly the same as ones in the MVC module, where the Store class is like this:

// <auto-generated> 
//     This code was generated from a template. 
//     Manual changes to this file may cause unexpected behavior in your application. 
//     Manual changes to this file will be overwritten if the code is regenerated. 
// </auto-generated> 
namespace WPF_DatabaseFirst  
 using System;  
 using System.Collections.Generic;  
 public partial class store  
 public string stor_id { get; set; }  
 public string stor_name { get; set; }  
 public string stor_address { get; set; }  
 public string city {