Chapter 8. Data Binding with Windows Forms and WPF Applications

So far, you’ve seen how to interact directly with an EDM using snippets of code in a console application. Although there is much more to learn about the Entity Framework, at this point it’s time to see how you can use the Entity Framework as part of your applications.

In this chapter, you will explore basic data-binding scenarios in Windows Forms and Windows Presentation Foundation (WPF). You’ll see how the Entity Framework objects work with Visual Studio’s data-binding features in much the same way that DataTables and DataSets do, without having to explicitly set and retrieve the values of each control. The data binding’s change notification mechanism works automatically with the Entity Framework’s change tracking, so editing data that was queried through the Entity Data Model does not require a lot of extra coding. In the examples here, you’ll bind directly to the results of Entity Framework queries as you learn the concepts. In Chapter 20, after you have learned much more about the Entity Framework, I will address n-tier Windows Forms applications.

The chapter will begin with data binding in Windows Forms and will then move on to the WPF techniques.

Data Binding with Windows Forms Applications

To demonstrate data binding of an EDM to a Windows form, let’s build a small application to let you view customers and their reservations as well as edit the customers and add new reservations. Figure 8-1 shows this form with a ...

Get Programming Entity Framework now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.