1.建立WPF應用程式
2.參考Step-By-Step教學(16):使用Object Service查詢 Entity Framework步驟1~5加入ADO.NET Data Model連接到Northwind資料庫,選所有資料表,完成精靈
3.加一個ListBox到Windows1.xaml
4.修改ListBox標籤
5.選取Windows,雙擊屬性視窗Loaded屬性
6.修改程式碼如下:
1 using System.Data.Objects;
2 using System.Collections.ObjectModel;
3 namespace EFWpf {
4 public partial class Window1 : Window {
5 public Window1() {
6 InitializeComponent();
7 }
8 NorthwindEntities context = new NorthwindEntities();
9 private List<Employees> employees;
10 private void Window_Loaded(object sender, RoutedEventArgs e) {
11 employees = context.Employees.ToList();
12 listBox1.ItemsSource = employees;
13 }
14 }
15 }
7.執行
沒有留言:
張貼留言