You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/data-tools/bind-wpf-controls-to-a-wcf-data-service.md
+23-33Lines changed: 23 additions & 33 deletions
Original file line number
Diff line number
Diff line change
@@ -20,23 +20,24 @@ ms.workload:
20
20
---
21
21
# Bind WPF controls to a WCF data service
22
22
23
-
In this walkthrough, you will create a WPF application that contains data-bound controls. The controls are bound to customer records that are encapsulated in a [!INCLUDE[ss_data_service](../data-tools/includes/ss_data_service_md.md)]. You will also add buttons that customers can use to view and update records.
23
+
In this walkthrough, you will create a WPF application that contains data-bound controls. The controls are bound to customer records that are encapsulated in a WCF Data Service. You will also add buttons that customers can use to view and update records.
24
24
25
25
This walkthrough illustrates the following tasks:
26
26
27
27
- Creating an Entity Data Model that is generated from data in the AdventureWorksLT sample database.
28
28
29
-
- Creating a [!INCLUDE[ss_data_service](../data-tools/includes/ss_data_service_md.md)] that exposes the data in the Entity Data Model to a WPF application.
29
+
- Creating a WCF Data Service that exposes the data in the Entity Data Model to a WPF application.
30
30
31
31
- Creating a set of data-bound controls by dragging items from the **Data Sources** window to the WPF designer.
32
32
33
33
- Creating buttons that navigate forward and backward through customer records.
34
34
35
-
- Creating a button that saves changes to data in the controls to the [!INCLUDE[ss_data_service](../data-tools/includes/ss_data_service_md.md)] and the underlying data source.
35
+
- Creating a button that saves changes to data in the controls to the WCF Data Service and the underlying data source.
You need the following components to complete this walkthrough:
41
42
42
43
- Visual Studio
@@ -54,9 +55,8 @@ Prior knowledge of the following concepts is also helpful, but not required to c
54
55
- WPF data binding. For more information, see [Data Binding overview](/dotnet/framework/wpf/data/data-binding-overview).
55
56
56
57
## Create the service project
57
-
Start this walkthrough by creating a project for a [!INCLUDE[ss_data_service](../data-tools/includes/ss_data_service_md.md)].
58
58
59
-
### To create the service project
59
+
Start this walkthrough by creating a project for a WCF Data Service:
60
60
61
61
1. Start Visual Studio.
62
62
@@ -66,16 +66,15 @@ Start this walkthrough by creating a project for a [!INCLUDE[ss_data_service](..
66
66
67
67
4. Select the **ASP.NET Web Application** project template.
68
68
69
-
5. In the **Name** box, type `AdventureWorksService` and click **OK**.
69
+
5. In the **Name** box, type **AdventureWorksService** and click **OK**.
70
70
71
-
Visual Studio creates the `AdventureWorksService` project.
71
+
Visual Studio creates the **AdventureWorksService** project.
72
72
73
73
6. In **Solution Explorer**, right-click **Default.aspx** and select **Delete**. This file is not necessary in this walkthrough.
74
74
75
75
## Create an Entity Data Model for the service
76
-
To expose data to an application by using a [!INCLUDE[ss_data_service](../data-tools/includes/ss_data_service_md.md)], you must define a data model for the service. The [!INCLUDE[ss_data_service](../data-tools/includes/ss_data_service_md.md)] supports two types of data models: Entity Data Models, and custom data models that are defined by using common language runtime (CLR) objects that implement the <xref:System.Linq.IQueryable%601> interface. In this walkthrough, you create an Entity Data Model for the data model.
77
76
78
-
### To create an Entity Data Model
77
+
To expose data to an application by using a WCF Data Service, you must define a data model for the service. The WCF Data Service supports two types of data models: Entity Data Models, and custom data models that are defined by using common language runtime (CLR) objects that implement the <xref:System.Linq.IQueryable%601> interface. In this walkthrough, you create an Entity Data Model for the data model.
79
78
80
79
1. On the **Project** menu, click **Add New Item**.
81
80
@@ -100,9 +99,8 @@ To expose data to an application by using a [!INCLUDE[ss_data_service](../data-t
100
99
8. Click **Finish**.
101
100
102
101
## Create the service
103
-
Create a [!INCLUDE[ss_data_service](../data-tools/includes/ss_data_service_md.md)] to expose the data in the Entity Data Model to a WPF application.
104
102
105
-
### To create the service
103
+
Create a WCF Data Service to expose the data in the Entity Data Model to a WPF application:
106
104
107
105
1. On the **Project** menu, select **Add New Item**.
108
106
@@ -113,23 +111,21 @@ Create a [!INCLUDE[ss_data_service](../data-tools/includes/ss_data_service_md.md
113
111
Visual Studio adds the `AdventureWorksService.svc` to the project.
114
112
115
113
## Configure the service
116
-
You must configure the service to operate on the Entity Data Model that you created.
117
114
118
-
### To configure the service
115
+
You must configure the service to operate on the Entity Data Model that you created:
119
116
120
-
1. In the `AdventureWorks.svc` code file, replace the `AdventureWorksService` class declaration with the following code.
117
+
1. In the `AdventureWorks.svc` code file, replace the **AdventureWorksService** class declaration with the following code.
This code updates the `AdventureWorksService` class, so that it derives from a <xref:System.Data.Services.DataService%601> that operates on the `AdventureWorksLTEntities` object context class in your Entity Data Model. It also updates the `InitializeService` method to allow clients of the service full read/write access to the `SalesOrderHeader` entity.
122
+
This code updates the **AdventureWorksService** class, so that it derives from a <xref:System.Data.Services.DataService%601> that operates on the `AdventureWorksLTEntities` object context class in your Entity Data Model. It also updates the `InitializeService` method to allow clients of the service full read/write access to the `SalesOrderHeader` entity.
126
123
127
124
2. Build the project, and verify that it builds without errors.
128
125
129
126
## Create the WPF client application
130
-
To display the data from the [!INCLUDE[ss_data_service](../data-tools/includes/ss_data_service_md.md)], create a new WPF application with a data source that is based on the service. Later in this walkthrough, you will add data-bound controls to the application.
131
127
132
-
### To create the WPF client application
128
+
To display the data from the WCF Data Service, create a new WPF application with a data source that is based on the service. Later in this walkthrough, you will add data-bound controls to the application.
133
129
134
130
1. In **Solution Explorer**, right-click the solution node, click **Add**, and select **New Project**.
135
131
@@ -155,7 +151,7 @@ To display the data from the [!INCLUDE[ss_data_service](../data-tools/includes/s
155
151
156
152
Visual Studio searches the current solution for available services, and adds `AdventureWorksService.svc` to the list of available services in the **Services** box.
157
153
158
-
9. In the **Namespace** box, type `AdventureWorksService`.
154
+
9. In the **Namespace** box, type **AdventureWorksService**.
159
155
160
156
10. In the **Services** box, click **AdventureWorksService.svc**, and then click **OK**.
161
157
@@ -165,10 +161,9 @@ To display the data from the [!INCLUDE[ss_data_service](../data-tools/includes/s
165
161
166
162
Visual Studio adds nodes that represent the data returned by the service to the **Data Sources** window.
167
163
168
-
## Define the user interface of the window
169
-
Add several buttons to the window by modifying the XAML in the WPF designer. Later in this walkthrough, you will add code that enables users to view and update sales records by using these buttons.
164
+
## Define the user interface
170
165
171
-
### To create the window layout
166
+
Add several buttons to the window by modifying the XAML in the WPF designer. Later in this walkthrough, you will add code that enables users to view and update sales records by using these buttons.
172
167
173
168
1. In **Solution Explorer**, double-click **MainWindow.xaml**.
174
169
@@ -189,9 +184,8 @@ Add several buttons to the window by modifying the XAML in the WPF designer. Lat
189
184
3. Build the project.
190
185
191
186
## Create the data-bound controls
192
-
Create controls that display customer records by dragging the `SalesOrderHeaders` node from the **Data Sources** window to the designer.
193
187
194
-
### To create the data-bound controls
188
+
Create controls that display customer records by dragging the `SalesOrderHeaders` node from the **Data Sources** window to the designer.
195
189
196
190
1. In the **Data Sources** window, click the drop-down menu for the **SalesOrderHeaders** node, and select **Details**.
197
191
@@ -228,9 +222,8 @@ Create controls that display customer records by dragging the `SalesOrderHeaders
228
222
- **Sales Order Number**
229
223
230
224
## Load the data from the service
231
-
Use the service proxy object to load sales data from the service. Then assign the returned data to the data source for the <xref:System.Windows.Data.CollectionViewSource> in the WPF window.
232
225
233
-
### To load the data from the service
226
+
Use the service proxy object to load sales data from the service. Then assign the returned data to the data source for the <xref:System.Windows.Data.CollectionViewSource> in the WPF window.
234
227
235
228
1. In the designer, to create the `Window_Loaded` event handler, double-click the text that reads: **MainWindow**.
236
229
@@ -240,9 +233,8 @@ Use the service proxy object to load sales data from the service. Then assign th
Copy file name to clipboardExpand all lines: docs/data-tools/create-a-sql-database-by-using-a-designer.md
+10-5Lines changed: 10 additions & 5 deletions
Original file line number
Diff line number
Diff line change
@@ -16,15 +16,16 @@ ms.workload:
16
16
- "data-storage"
17
17
---
18
18
# Create a database and add tables in Visual Studio
19
+
19
20
You can use Visual Studio to create and update a local database file in SQL Server Express LocalDB. You can also create a database by executing Transact-SQL statements in the **SQL Server Object Explorer** tool window in Visual Studio. In this topic, we'll create an *.mdf* file and add tables and keys by using the Table Designer.
20
21
21
22
## Prerequisites
23
+
22
24
To complete this walkthrough, you must have the optional **Data storage and processing** workload installed in Visual Studio. To install it, open **Visual Studio Installer** and choose the **Workloads** tab. Under **Web & Cloud**, choose **Data storage and processing**. Choose the **Modify** button to add the workload to Visual Studio.
23
25
24
26
## Create a project and a local database file
25
27
26
-
### To create a project and a database file
27
-
1. Create a Windows Forms project that's named `SampleDatabaseWalkthrough`.
28
+
1. Create a Windows Forms project that's named **SampleDatabaseWalkthrough**.
28
29
29
30
2. On the menu bar, select **Project** > **Add New Item**.
30
31
@@ -35,6 +36,7 @@ To complete this walkthrough, you must have the optional **Data storage and proc
35
36
4. Name the database **SampleDatabase**, and then select the **Add** button.
36
37
37
38
### To add a data source
39
+
38
40
5. If the **Data Sources** window isn't open, open it by selecting the **Shift**+**Alt**+**D** keys or, on the menu bar, select **View** > **Other Windows** > **Data Sources**.
39
41
40
42
6. In the **Data Sources** window, select the **Add New Data Source** link.
@@ -52,16 +54,19 @@ To complete this walkthrough, you must have the optional **Data storage and proc
52
54
11. One the **Choose your Database Objects** page, you'll see a message that says the database doesn't contain any objects. Choose **Finish**.
53
55
54
56
### To view properties of the data connection
57
+
55
58
You can view the connection string for the *SampleDatabase.mdf* file by opening the properties window of the data connection:
56
59
57
60
- In Visual Studio, select **View** > **SQL Server Object Explorer** if that window isn't already open. Open the properties window by expanding the **Data Connections** node, opening the shortcut menu for *SampleDatabase.mdf*, and then selecting **Properties**.
58
61
59
62
- Alternatively, you can select **View** > **Server Explorer**, if that window isn't already open. Open the properties window by expanding the **Data Connections** node. Open the shortcut menu for *SampleDatabase.mdf*, and then select **Properties**.
60
63
61
64
## Create tables and keys by using Table Designer
65
+
62
66
In this section, you'll create two tables, a primary key in each table, and a few rows of sample data. You'll also create a foreign key to specify how records in one table correspond to records in the other table.
63
67
64
68
### To create the Customers table
69
+
65
70
1. In **Server Explorer** or **SQL Server Object Explorer**, expand the **Data Connections** node, and then expand the **SampleDatabase.mdf** node.
66
71
67
72
2. Open the shortcut menu for **Tables**, and then select **Add New Table**.
@@ -98,6 +103,7 @@ In this section, you'll create two tables, a primary key in each table, and a fe
98
103
Your changes are saved to the local database file.
99
104
100
105
### To create the Orders table
106
+
101
107
1. Add another table, and then add a row for each entry in the following table:
102
108
103
109
|Column name|Data type|Allow nulls|
@@ -122,11 +128,12 @@ In this section, you'll create two tables, a primary key in each table, and a fe
122
128
Your changes are saved to the local database file.
123
129
124
130
### To create a foreign key
131
+
125
132
1. In the context pane on the right side of the grid, open the shortcut menu for **Foreign Keys**, and then select**Add New Foreign Key**, as the following illustration shows.
126
133
127
134

128
135
129
-
2. In the textbox that appears, replace **ToTable** with `Customers`.
136
+
2. In the textbox that appears, replace **ToTable** with **Customers**.
130
137
131
138
3. In the T-SQL pane, update the last line to match the following sample:
132
139
@@ -142,8 +149,6 @@ In this section, you'll create two tables, a primary key in each table, and a fe
142
149
143
150
## Populate the tables with data
144
151
145
-
### To populate the tables with data
146
-
147
152
1. In**Server Explorer**or**SQL Server Object Explorer**, expand the node for the sample database.
148
153
149
154
2. Open the shortcut menu for the **Tables** node, select**Refresh**, and then expand the **Tables** node.
0 commit comments