Suchen und Finden
Contents at a Glance
5
Table of Contents
6
About the Author
12
About the Technical Reviewer
13
Acknowledgments
14
CHAPTER 1 Introducing the ADO.NET 4.0 Entity Framework
15
The Need for an Entity Framework
15
This Has Been Tried Before
17
So, What Is the Entity Framework?
18
Database vs. Model
19
Database-Driven
19
Model-Driven
20
Working with Entities
21
Entity Framework 4.0 Features
23
POCO Support
24
Model-First Support
24
Related Object–Deferred Loading
24
LINQ-to-Entities Function Support
24
Plurality Naming
24
Complex Types
25
Customized Object-Layer Code Generation
25
Model Browser Improvements
25
Back-End Support
26
CHAPTER 2 The Entity Data Model
27
Creating an EDM
27
Taking a Database-First Approach
28
Making Generated Object Names Plural or Singular
33
Taking a Model-First Approach
36
Generating a Schema and Database
41
Managing Table Inheritance
45
Taking a Code-Only Approach
46
CHAPTER 3 The Entity Data Model Inside and Out
48
The Designer Window and the EDM
48
The Designer Window
48
Model Browser Window
50
Mapping Details Window
51
Entities
51
Scalar Properties
53
Complex Types
53
Complex Types Defined
54
Creating a Complex Type
54
Foreign Keys and Relationships (Associations)
58
Navigation Properties
59
Mapping Details
60
Lifting the EDM Hood
61
The EDM Model Parts
63
The SSDL Section
63
EntityType Element
65
Association Element
65
The CSDL Section
66
EntityType Element
67
Associations
68
The CS (MSL) Section
69
EDM-Generated Classes
71
CHAPTER 4 Querying the EDM
75
Querying with the Entity Framework
75
Syntax Options
75
Query-Expression Syntax
75
Context
79
Method-Based Syntax
80
Querying Options
81
LINQ to Entities
81
Entity SQL
86
The EntityClient
88
EntityConnection
89
EntityCommand
90
Immediate vs. Deferred Query Execution
90
Deferred Execution
91
Immediate Execution
92
CHAPTER 5 Working with Entities
94
The ObjectContext
94
ObjectStateEntry
94
Tracking and Saving Changes
95
Updating Entities
96
Adding Entities
98
Relational Inserts
100
Deleting Entities
102
CHAPTER 6 Stored Procedures and the EDM
104
Stored Procedures in the EDM
104
The Model Browser
108
What Is an EF Function?
109
Mapping Functions
110
Functions (Stored Procedures) in Action
113
Insert
113
Update
115
Delete
116
Select
116
Using Functions in Queries
117
CHAPTER 7 Relationships and Associations
120
Overview
120
Relationships in General
120
Relationships in EF 3.5
121
EF 4.0 Relationships
124
Creating a WinForms Project
124
Defining Referential Constraints
127
Adding an Association
127
Looking at XML Differences
128
Understanding Approaches to Foreign Keys in EF 4.0
130
Using FK Associations in Code
131
Adding Dependent Objects
131
Manually Setting the Foreign Key Property
132
Setting the Foreign Key Automatically
133
Building the Sample Project
134
Summary
137
CHAPTER 8 T4 Code Generation
138
T4 Template Overview
138
Adding a Template Using Visual Studio 2008
138
Installing a T4 Editor
139
Writing Some T4 Code
140
Scoping Your Code
143
Example 1: Running the Project
144
Example 2: Returning Your Computer’s Processes
145
Example 3: Listing Your SQL Databases
146
T4 Templates and the Entity Framework
148
T4 Customization Example
153
CHAPTER 9 Model-First Development
155
Model-First Design
155
Creating a Conceptual Model
155
Creating Entities in the Empty Model
158
Creating Associations and Navigation Properties
160
Saving the Model
161
Verifying Compilation
162
Creating the Mappings and Database
162
Database Generation Rules
169
Tables
169
Association
170
Handling of Complex Types
171
DB Generation Script Customization
173
CHAPTER 10 Code-Only Development
177
Getting Started with Code-Only
177
Creating the Data Project
178
Adding the User-Interface Project
180
Adding References
180
Adding Context and Connections
182
Coding the User Interface
183
Creating Configuration Classes
183
Testing the Code-Only Model
185
Building the Project
186
Loading Some Rows
187
Connecting the DataGridView Control
188
Running the Application
189
Overcoming Restrictions in EF 3.5
190
Additional POCO Information
190
Complex-Type Support
191
Lazy Loading
192
Change Tracking
192
Finishing the Example
193
CHAPTER 11 N-tier Development with WCF Data Services
197
Building the WCF Data Service
197
Testing the WCF Data Service
204
Consuming the WCF Data Service
211
Adding the Service Reference
212
Utilizing the Service
216
CHAPTER 12 Performance Tuning and Exception Handling
219
Updating the Model
219
Checking the Model
223
Stored Procedure Mapping
225
Building an Entity Framework Project
226
Exception Handling
229
Try/Catch Blocks
229
The Using Statement
231
Exception Class
231
Connection Exceptions
233
Query Exceptions
235
EntitySQL Exceptions
236
CHAPTER 13 Data Binding with the Entity Framework
238
Windows Forms Data Binding
238
Creating a Project Directory
238
Creating a New Form
238
Creating Data Sources
241
Adding Code to the Form
245
Adding a Grid Control
247
Getting the Grid to Display Some Data
248
Helping the Grid to Navigate the Relation
250
Testing Your Final Grid Implementation
250
Implementing Add, Delete, and Save Functionality
251
Implementing Add Functionality
251
Implementing Delete Functionality
253
Implementing Save Functionality
253
WPF Data Binding
254
Creating a Project
254
Adding Some Code
254
Running the Project
255
Displaying Related Detail
257
Index
261
Alle Preise verstehen sich inklusive der gesetzlichen MwSt.