آموزشگاه برنامه نویسی تحلیل داده
آموزشگاه برنامه نویسی تحلیل داده
آموزشگاه برنامه نویسی تحلیل داده
آموزشگاه برنامه نویسی تحلیل داده

آموزش Programming Entity Framework : Entity Framework

  • عنوان :

    آموزش Programming Entity Framework : Entity Framework

  • نویسنده : Julia Lerman

دوره آموزش Entity Framework


سرفصل آموزشی این کتاب به شرح زیر است:

Table of Contents
Foreword . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxi
Preface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxiii
1. Introducing the ADO.NET Entity Framework . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
Programming Against a Model, Not Against the Database 2
The Entity Data Model: A Client-Side Data Model 3
The Entity in “Entity Framework” 5
Choosing Your Backend 8
Available Providers 8
Access and ODBC 9
Entity Framework Features 9
The Entity Data Model 9
Entity Data Model Design Tools 9
Managing Objects with Object Services 10
Change Tracking 11
Relationship Management 11
Data Binding 12
EntityClient 12
The Entity Framework in Web Services 12
What About ADO.NET DataSets and LINQ to SQL? 13
DataSets 13
LINQ to SQL 14
Entity Framework Pain Points 14
The Entity Framework Designer 14
Challenges with Change Tracking Distributed Applications 16
Domain-Driven Development 16
Unit Testing 16
Programming the Entity Framework 17
2. Exploring the Entity Data Model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
Why Use an Entity Data Model? 19

The EDM Within the Entity Framework 20
Your First EDM 21
The EDM in the Designer Window 23
Entity Properties 25
Editing the Entity Set and Navigation Property Names 26
The Naked Model: Inspecting the Model’s XML 27
A Less Daunting Model View 27
The Three Parts of the Model 28
CSDL: The Conceptual Schema 30
Schema 31
EntityContainer 31
EntitySet 32
EntityType 33
Associations 35
AssociationSet 37
NavigationProperty 38
Navigation Properties That Return Collections 39
Where Are the Foreign Keys? 41
SSDL: The Store Schema 41
Association and AssociationSet 43
MSL: The Mappings 45
The MSL Elements 46
Database Views in the EDM 49
Code Generation from EDM to Classes 50
Summary 50
3. Querying Entity Data Models . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51
Query the Model, Not the Database 51
Your First EDM Query 52
A More Query-Like Query 53
Where Did the Context and Classes Come from? 54
LINQ to Entities Queries 56
ObjectQuery and LINQ to Entities 57
Entity SQL Queries That Return Objects 59
Why Another Way to Query? 59
Entity SQL 60
The Parameterized ObjectQuery 62
Method-Based Syntax Queries for LINQ and Entity SQL 63
LINQ Method-Based Queries 63
ObjectQuery’s Query Builder Methods 66
The Shortest Query 67
EntityClient: The Lowest-Level Method for Returning Streamed Data
Through EDM Queries 68

EntityConnection and the Connection String 70
EntityCommand 71
ExecuteReader 71
Forward-Only Access to the Fields 71
Translation to Database Queries 72
Pay Attention to the .NET Method’s Impact on Generated SQL 73
Avoid Inadvertent Query Execution 74
Summary 75
4. Exploring EDM Queries in Greater Depth . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77
Same Model, Friendlier Name 78
Projections in Queries 79
Projections in LINQ to Entities 80
LINQ Projections and New Language Features 80
Projections with LINQ Query Methods 84
Projections in Entity SQL 84
DbDataRecords and Nonscalar Properties 86
Projecting with Query Builder Methods 87
Querying Across Associations 87
Navigation to an EntityReference 88
Filtering and Sorting with an EntityReference 90
Navigating to Entity Collections 91
Projecting Properties from EntityCollection Entities 92
Filtering and Sorting with EntityCollections 93
Aggregates with EntityCollections 94
Entity SQL SET Operators 96
Aggregates in LINQ Methods and Query Builder Methods 96
Joins and Nested Queries 97
Joins 97
Nested Queries 99
Grouping 101
Naming Properties When Grouping 103
Chaining Aggregates 103
Filtering on Group Conditions 104
Grouping in Entity SQL 105
Shaped Data Returned by Queries 107
Shaped Data from Entity SQL 109
Deferred Loading and Eager Loading Queries 111
Deferred Loading Entity Collections with Load 111
Using the Include Method to Eager-Load 113
Using Include with an ObjectQuery 115
Pros and Cons of Load and Include 116
Retrieving a Single Entity 117

Retrieving a Single Entity with GetObjectByKey 118
Entity SQL’s Wrapped and Unwrapped Results 118
Entity SQL Rules for Wrapped and Unwrapped Results 121
Digging a Little Deeper into EntityClient’s Results 121
Summary 122
5. Modifying Entities and Saving Changes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 123
How ObjectContext Manages Entities 123
Remembering Original Values and Keeping Track of Changes 124
The SaveChanges Method 124
From Entity Framework Command to Native Command 127
Adding New Entities 127
Breaking Down the Native Insert Command 128
Inserting New Parents and Children 129
Deleting Entities 131
Summary 132
6. Using Stored Procedures with the EDM . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 133
Adding the Stored Procedures into the Model 133
Working with Functions 135
Function Attributes 136
Implementing Functions 138
Rules for Mapping Functions to Entities 139
Wiring Up Insert, Update, and Delete Functions to an Entity 139
Inspecting the Mappings in the XML 141
Using These Mapped Functions 143
The EDM Designer’s Model Browser 144
Mapping the Last of the Four Functions: CustomersbyState 145
Using the CustomersbyState Function 146
Using Functions in a Query 147
More About the Update Model Wizard 148
A Frequently Asked Question About Deleting Entities from the Model 148
Summary 149
7. Tuning Up a Model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 151
The BreakAway Geek Adventures Business Model 151
Creating a Class Library Project to Host an EDM 152
Inspecting and Cleaning Up a New Model 153
Modifying the Names of Entities 154
Collisions Between Property Names and Entity Names 155
Cleaning Up Navigation Property Names 156
Entities with Multiple Relationships to a Single Entity 157

Determining Which Navigation Property Is Mapped to Which Foreign
Key Field 158
Mapping a Few Stored Procedures 159
Mapping the Insert Function 159
Mapping the Update Function 160
Working with Many-to-Many Relationships 163
Building the BreakAwayModel Project 165
Don’t Overlook the Assembly and Model Names 165
The Impact of Compiling a Project on an EDMX File 166
Summary 168
8. Data Binding with Windows Forms and WPF Applications . . . . . . . . . . . . . . . . . . . 169
Data Binding with Windows Forms Applications 169
Creating a Windows Forms Application 170
Using Windows Forms Data Sources to Help with Data Binding 171
Creating an Object Data Source for a Customer Entity 172
Getting the Entity’s Details onto the Form 175
Adding Code to Perform the EDM Query 175
Testing the Sample 178
Entities, BindingSources, and a Very Important Rule 178
Adding the Related EntityCollection to the Form 179
Allowing the User to Edit the Data 183
Editing the Navigation Properties (and Trimming Down the Query) 184
Adding New Customers 188
Data Binding with WPF Applications 193
Creating the WPF Form 194
Creating the New Project 194
Adding Code to Query the Entities That Drive the Form 195
XAML’s Role in Data Binding 197
Binding with the ListBox 197
Testing the Example 199
Selecting an Entity and Seeing Its Details 199
Adding Another EntityCollection to the Mix: Activities 201
Editing Trip Entities and Their Related Data 204
Adding Items to the Child EntityCollection 207
The Last Task: Adding New Trips to the Catalog 209
Summary 213
9. Working with Object Services . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 215
Where Does Object Services Fit into the Framework? 215
Query Processing 216
From Query to Command Tree to SQL 217
A Better Understanding of Query Builder Methods 218

Breaking Apart the ObjectQuery 222
Query Execution with the ToList or ToArray Method 224
Query Execution with the Execute Method 225
ObjectContext.Connection 225
Handling Command Execution with EntityClient 227
Object Materialization 227
The ObjectContext 227
ObjectContext Is a Cache for In-Memory Objects 228
Entity Objects 229
EntityKey and EntityState 231
Merging Results into the Cache 232
State Management and ObjectStateEntry 233
Change Tracking 234
Relationship Management 236
Attaching and Detaching Objects from the ObjectContext 237
ObjectContext.ApplyPropertyChanges: A Handy Method for Updating
Entities 240
Sending Changes Back to the Database 241
ObjectContext.SaveChanges 241
SaveChanges Returns an Integer 241
Data Validation with the SavingChanges Event 242
Concurrency Management 242
Transaction Support 243
Additional Features 244
Object Services Supports XML and Binary Serialization 244
Object Services Supports Data Binding 246
Object Services Supports Custom Classes 247
Summary 248
10. Customizing Entities . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 249
Partial Classes 249
Customizable Methods 251
The OnContextCreated Method 251
The On[Property]Changed and On[Property]Changing Methods 253
Using PropertyChanged to Calculate Database-Computed Columns
Locally 255
Customizable Event Handlers 257
The ObjectContext.SavingChanges Event 257
The EntityObject.PropertyChanging and EntityObject.Property-
Changed Events 260
The AssociationChanged Event 262
Other Opportunities for Customization 265
Custom Properties 265

Custom Properties That Perform Calculations on Child Collections 267
Overloading Context and Entity Methods 268
Partial Classes Are for More Than Just Overriding Existing Methods
and Events 269
Custom Code Generation 269
Creating Common Methods or Properties for All Entities 269
Summary 270
11. Using the ASP.NET EntityDataSource Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 271
Getting to First Base with the EntityDataSource Control and Flat Data 272
Creating the Hello Entities Project 272
Creating a GridView and an EntityDataSource Concurrently 273
Configuring an EntityDataSource Through Its Wizard 274
Formatting the GridView 276
Testing the Web Application 277
Understanding How the EntityDataSource Is Able to Retrieve and Update
Your Data 278
EntityDataSource and Its Query 278
EntityDataSource and Its ObjectContext 279
EntityDataSource Context Events 280
EntityDataSource and ViewState 281
Working with Related EntityReference Data 282
Using EntityDataSource.Include to Get Related Data 283
Displaying Data That Comes from EntityReference Navigation
Properties 284
Using a New EntityDataSource Control to Enable Editing of
EntityReference Navigation Properties 285
Editing EntityReferences That Cannot Be Satisfied with a Drop-Down
List 287
Binding an EntityDataSource to Another Control with
WhereParameters 287
Editing Related Data Concurrently with Multiple EntityDataSource
Controls 289
Working with Hierarchical Data in a Master/Detail Form 290
Setting Up the Web Application 290
Specifying Your Own Entity SQL Query Expression for an EntityData-
Source 291
Binding a DropDownList to an EntityDataSource Control 292
Creating a Parent EntityDataSource That Is Controlled by the Drop-
DownList and Provides Data to a DetailsView 293
Using the EntityDataSource.Where Property to Filter Query Results 294
Displaying Read-Only Child Data Through the Parent EntityDataSource 294

Using a New EntityDataSource to Add a Third Level of Hierarchical
Data to the Master/Detail Form 296
Using the EntityDataSource.Inserting Event to Help with Newly Added
Entities 298
Testing the Application 299
Browsing Through the EntityDataSource Events 300
EntityDataSource Events and Page Events 300
Summary 302
12. Customizing Entity Data Models . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 303
Designer Support for Mappings 303
Mapping Table per Type Inheritance for Tables That Describe Derived
Types 304
Mapping TPT Inheritance 305
Fixing the Impact of the New Inheritance on the Customer’s Associations
with Other Entities 306
Handling Properties with the Same Name 309
Querying Inherited Types 310
Creating a Project to Test the New Mappings 310
Testing the TPT Inheritance 311
SaveChanges and Newly Added Derived Types 312
Specifying or Excluding Derived Types in Queries 313
Creating New Derived Entities When the Base Entity Already Exists 314
TPT with Abstract Types 315
Using Entity Splitting to Map a Single Entity to More Than One Table 318
Merging Multiple Entities into One 319
Testing Entity Splitting 319
Using Conditional Mapping to Filter Entity Mappings 322
Creating a Conditional Mapping for the Activity Entity 323
Testing the Conditional Mapping 325
Implementing Table per Hierarchy Inheritance for Tables That Contain
Multiple Types 328
Creating the Resort Derived Type 328
Setting a Default Value on the Table Schema 330
Testing the TPH Mapping 331
Abstract Entity Types 332
Which of These Mappings Is Better? 333
Implementing Customizations That Are Not Supported by the EDM
Designer 334
Mapping Table per Concrete (TPC) Type Inheritance for Tables with
Overlapping Fields 334
Creating Complex Types to Encapsulate Sets of Properties 336
Complex Types and the EDM Designer 337

Defining a Complex Type 337
Replacing Properties with a Complex Type 338
Mapping Entities with Complex Types 339
Complex Types Are Not EntityObjects 339
Using Complex Types 340
Complex Types in Data-Binding Scenarios 341
Data Binding Complex Types in ASP.NET Without the EntityData-
Source 343
Windows Forms DataSource and Complex Types 345
Removing the Complex Types from the Model 347
Using QueryView to Create Read-Only Entities and Other Specialized
Mappings 348
Creating a Simple QueryView 349
Testing the QueryView 351
Deconstructing the QueryView 351
QueryView with Inherited Types 352
Testing the New QueryView 354
Additional Customization Options 355
Mapping Stored Procedures 355
Multiple Entity Sets per Type 356
Self-Referencing Associations 356
Summary 356
13. Working with Stored Procedures When Function Mapping Won’t Do . . . . . . . . . . 359
Does the Procedure Line Up with an Entity? 359
Overview of Procedures, UDFs, and TVFs in the EDM 360
Composing Queries Against Functions 360
Mapping and Executing Query Stored Procedures 361
Using Functions That Match an Entity Whose Property Names Have
Been Changed 361
Query Stored Procedures and Inherited Types 362
Queries That Return Randomly Shaped Results 363
Replacing Stored Procedures with Views 364
Queries That Return Multiple Resultsets 366
Queries That Return Primitive Types 366
Adding Native Queries to the Model 367
Adding Native Views to the Model 368
DefiningQuery Is Already in Your Model 369
Using DefiningQuery to Create Your Own Views 372
Implementing a DefiningQuery 373
Using DefiningQuery to Solve More Complex Problems 378
Using Commands That Affect the Persisted Database 378
DML Functions That Return Entities 379

Insert, Update, and Delete Functions That Don’t Return an Entity 381
Defining Insert, Update, and Delete Stored Procedures Directly in the
Model 382
What Do the Functions Look Like? 382
Mapping Insert/Update/Delete to Types Within an Inheritance Structure 383
What If Stored Procedures Affect Multiple Entities in an Inheritance
Structure? 384
Implementing and Querying with User-Defined Functions (UDFs) 385
Summary 386
14. Using Entities with Web and WCF Services . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 389
Building a Client That Is Ignorant of the Entity Framework 389
Pros and Cons of an Entity Framework-Agnostic Consumer 390
Using the Entity Framework with ASMX Web Services 391
Building the ASMX Service 391
Building the Client Application 405
Using the Entity Framework with WCF Services 413
Building the WCF Service 414
Building the Client to Consume the WCF Service 432
Summary 445
15. Working with Relationships and Associations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 447
Deconstructing Relationships in the Entity Data Model 448
How Did the Entity Data Model Wizard Create the Association? 450
Additional Items Created in the Model 452
Navigation Properties Are Not Required 452
Understanding How Associations Impact the Native Query 453
Deconstructing Relationships Between Instantiated EntityObjects 454
Relationships Are First-Class Citizens 454
The “Platinum Rule” About Related Entities That Are Attached or
Detached from the ObjectContext 455
The Relationship Manager and the IRelatedEnd Interface 456
Experimenting with Relationship Span 457
Understanding Navigation Properties in Entity Objects 459
Referential Integrity and Constraints 462
Deletes and Cascading Deletes 463
Defining Relationships Between Entities 465
The CLR Way: Setting a Navigation Property 466
Setting an EntityReference Using an EntityKey 466
Loading, Adding, and Attaching Navigation Properties 467
EntityReference.Load and EntityCollection.Load 467
EntityCollection.Add 472
Attach and Remove 474

Attach Versus Add 475
Moving an Entity to a New Graph 475
Learning a Few Last Tricks to Make You a Relationship Pro 476
Using CreateSourceQuery to Enhance Deferred Loading 476
Getting a Foreign Key Value 478
Summary 479
16. Making It Real: Connections, Transactions, Performance, and More . . . . . . . . . . . 481
EntityConnection and Database Connections in the Entity Framework 481
EntityConnection Versus Database Connection 482
Programming EntityConnection Strings 483
Using the EntityConnectionStringBuilder Class 484
Opening and Closing Entity and Database Connections 486
Taking Control of How Store Connections Are Disposed 488
What About Connection Pooling? 490
The Entity Framework and Transactions 490
Why Use Your Own Transaction? 490
Understanding the Entity Framework’s Default: Implicit Transactions 491
Specifying Your Own Transaction 493
Reading Queries Using System.Transaction or EntityTransaction 496
Can You Use Transactions Within ObjectContext? 497
The Entity Framework and Security 497
SQL Injection 498
Protecting Data from Connection Piggybacks 500
The Entity Framework and Performance 501
A Few “Backyard Benchmarks” 501
Reducing the Cost of Query Compilation 507
The EDM Generator for Precompiled Views (and More) 508
Precompiled LINQ to Entities Queries 510
Query Plan Caching for Entity SQL 513
What About Database Updates and Performance? 515
Entities in Multithreaded Applications 516
Forcing an ObjectContext to Use Its Own Thread 517
Another Spin on Threading: Concurrent Processing 520
Summary 523
17. Controlling Objects with ObjectStateManager and MetadataWorkspace . . . . . . . 525
Managing ObjectStateEntry Objects with ObjectStateManager 526
An ObjectStateEntry Refresher 526
Getting an ObjectStateManager and Its Entries 527
Getting Groups of Entries with GetObjectStateEntries 527
Getting a Single Entry with GetObjectStateEntry and TryGetObject-
StateEntry 531

Digging Through ObjectStateEntry 532
CurrentValues and OriginalValues 532
CurrentValueRecord.DataRecordInfo 534
Building the ObjectStateEntry Visualizer 535
Setting Up the Project and Code File 536
Retrieving an ObjectStateEntry Using an EntityKey 537
Reading the OriginalValues and CurrentValues of an ObjectStateEntry 538
Determining Whether a Property Has Been Modified 539
Displaying the ObjectStateEntry’s State and Entity Type 540
Getting ComplexType Properties Out of ObjectStateEntry 541
Modifying Values with ObjectStateManager 543
Working with Relationships in ObjectStateManager 544
ObjectStateManager and SavingChanges 549
The FieldMetadata Hierarchy 551
The MetadataWorkspace API 552
Loading the MetadataWorkspace 552
Clearing the MetadataWorkspace from Memory 554
The MetadataWorkspace ItemCollections 554
ItemCollections Are Loaded as Needed with EntityCollection 555
Reading Metadata from the MetadataWorkspace 556
Querying the Items 559
Building Entity SQL Queries Dynamically Using Metadata 559
Reading the Results of a Dynamically Created Query 563
Dynamic Entity SQL and Generics for Reference Lists 567
Creating EntityObjects Without Entity Classes 569
Creating a New Entity with CreateInstance 570
Using System.Type to Inspect the EntityType 571
Creating Entities and Graphs Dynamically 571
Calling the AddChildtoParentObject Method 574
Summary 575
18. Handling Entity Framework Exceptions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 577
Preparing for Exceptions in Entity Framework Code 578
EntityConnectionString Exceptions 580
Connection String Can’t Be Found or Is Improperly Configured:
System.ArgumentException 580
Metadata Files Cannot Be Found: System.Data.MetadataException 580
Handling Connection String Exceptions 581
Query Compilation Exceptions 582
Invalid LINQ to Entities Query Expressions: System.NotSupportedException
582
Invalid Entity SQL Query Expressions: EntitySQLException 582
Store Provider Issues: EntityCommandCompilationException 584

Creating a Common Wrapper to Handle Query Execution Exceptions 585
SaveChanges Command Execution Exceptions 587
Model and Mapping Constraints Are Broken: UpdateException 587
Exceptions Thrown by Broken Constraints in the Database 588
Automatically Rolling Back SaveChanges When an UpdateException
Occurs 589
ObjectStateEntries Returned by Object Services Exceptions 589
General Entity Exceptions That May Occur When Executing Queries
or Commands 590
InvalidOperationExceptions 590
Exceptions When Multiple Parties Edit Data Concurrently 591
Handling Concurrency Conflicts 591
Understanding Optimistic Concurrency Options in the Entity
Framework 592
Ignoring Concurrency Conflicts 592
Forcing the User’s Data to the Server (ClientWins) 593
Refreshing the User’s Data with Server Data (StoreWins) 593
Determining the Scope of Changes 593
Using rowversion for Concurrency Checks 594
Implementing Optimistic Concurrency with the Entity Framework 595
Flagging a Property for Concurrency Checking 595
How the Entity Framework Uses the ConcurrencyMode Property 595
Concurrency Checking Without a rowversion Field 597
Concurrency Checking on a Checksum in the Data Store 597
Concurrency Checks for EntityReference Navigation Properties 598
Concurrency Checks and Inherited Types 598
Concurrency Checks and Stored Procedures 600
Handling OptimisticConcurrencyExceptions 602
Using ObjectContext.Refresh 602
Using ClientWins Refresh 603
Using StoreWins Refresh 605
Refreshing Collections of Entities 606
Refreshing Related Entities in a Graph 608
Rewinding and Starting Again, and Maybe Again After That 609
What If a Relationship, But No Scalar Properties, Changes? 611
Reporting an Exception 612
Handling Concurrency Exceptions at a Lower Level 613
Handling Granular Exceptions Without User Intervention 613
Handling Multiple Conflicts 616
Handling Exceptions When Transactions Are Your Own 617
Summary 619

19. Using Your Own Custom Classes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 621
Mapping Classes to the Entity Data Model 621
Mapping Rules for Custom Classes and Their Properties 622
Inheriting from EntityObject 622
Metadata Attributes 623
Entity Classes 624
Scalar Properties 625
Navigation Properties 627
Mapping the Remaining Entities in the Model 631
Mapping the EntityContainer 631
Resolving Conflicts Between Custom Classes and Designer-Generated
Classes 631
Querying Using the Custom Classes 631
Implementing the IPOCO Interfaces 632
The IEntityWithKey Interface 632
The IEntityWithChangeTracker Interface 633
The IEntityWithRelationships Interface 636
Working with the IPOCO-Enabled Objects 637
Custom Class Assemblies and Entity Data Model Files 638
Accessing the Model Files When They Are Not in a Referenced
Assembly 639
Summary 639
20. Using the Entity Framework in n-Tier Client-Side Applications . . . . . . . . . . . . . . . . 641
Thinking in Layers 641
Organizing Your Layers 643
Finding Your Motivation: A Master/Detail Data Entry Form That Will Use
the DataBridge Class 644
Preventing Non-UI Logic from Leaking into the UI 644
Implementing Logic That Fits Best in the Entity Partial Classes 646
Creating an IsDirty Property for the ObjectContext 647
Building the CommandExecutor Class 648
Building the DataBridge Class 652
Using a Long-Running ObjectContext 652
Implementing the Primary Elements of the DataBridge Class 653
Creating a Class for Lightweight Objects to Be Used in UI Pick Lists 654
Creating the Main Entity Pick List: For Customer Names 655
Using MergeOptions to Cache or Refresh a Pick List 656
Building a Frequently Used Entity Graph for the UI 656
Supplying Additional Lists for UI Drop-Downs 660
Saving Changes 662
Rolling Back User Changes 663
Using the DataBridge Class for Data Binding in a Master/Detail Form 666

Using BindingSourceControls with the DataBridge 666
Instantiating the DataBridge Class in the Form 666
Populating the Form with an Entity and Its Related Data 667
Consuming the Pick Lists in the Form 669
Deleting from Grids When EntityCollections and Referential Constraints
Are Involved 670
Allowing Users to Roll Back Their Edits 675
Helping the User Who Forgets to Save Changes 676
Summary 677
21. Using the Entity Framework in n-Tier ASP.NET Applications . . . . . . . . . . . . . . . . . . 679
Understanding How an ObjectContext Fits into the Web Page Life Cycle 680
Using EntityObjects in Read-Only Web Pages 681
Exploring Options for Updating Entities in an ASP.NET Application 684
Evaluating ASP.NET’s State Solutions Against the Entity Framework 685
Introducing ASP.NET’s ObjectDataSource Control 689
Why ObjectDataSource? 689
ObjectDataSource Enforces Its Rules on Your Objects 689
How the ObjectDataSource Gets Data into and out of the Data-Binding
Controls 690
Designing Object Provider Classes to Be Used with an ObjectDataSource 691
Creating the CustomerProvider Class 692
Creating the AddressProvider Class 697
Creating the ReservationsProvider Class 701
Providing Reusable, Cached Reference Lists 702
Wiring Up the Provider Classes to ObjectDataSource Controls 704
Using the ObjectDataSource Wizard to Perform the Initial Wiring to
the Provider Classes 705
Tweaking ObjectDataSource Properties to Work with Entities 705
Using ObjectDataSource Events to Solve Problems That Are Particular
to Entities 706
Understanding Why We Didn’t Use Object Graphs in This Business Layer 713
Database Hits Versus Very Busy Memory 713
Summary 714
22. Implementing a Smarter WCF Service for Working with Entities . . . . . . . . . . . . . . 717
Will Your Client Agree to Your Data Contract? 718
Shipping DTOs, Not EntityObjects 719
Building a Data Transfer Object to Take the Place of an Entity Object 719
Creating EntityState Properties That Do Not Rely on ObjectContext 722
The EntityStateLocal Enums and Interface 723
Implementing the IEntityStateLocal Interface in the DTO Classes 724
Implementing the IEntityStateLocal Interface in the Entity Classes 724

Designing the Service Interface 725
Implementing the Service Operations 726
Returning CustomerList as ShortCustomers with GetCustomerList 727
Returning Additional Reference Lists 727
Returning a Single Entity Graph for Editing with GetCustomer 728
Building Methods to Create DTOs from Entity Objects 730
Initializing the DTO Children 732
Saving Edits Sent Back from the Client with SaveCustomer 733
Building the Main Method for Updating the Graph: SaveCustomer 735
UpdateChildren 740
Implementing the Client That Will Use the WCF Service 742
Rules for the Client to Follow 742
Building a Business Layer Between the UI and the Services 743
What’s in These Business Classes? 743
Calling the Service Operations from the Business Layer 747
Testing It All with a Simple Console Application 749
Summary 751
23. The Entity Framework, Today and Tomorrow . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 753
What About Building Reports with the Entity Framework? 753
Major Differences Between the Entity Framework and LINQ to SQL 754
Extensions, Samples, and Solutions from Microsoft 755
Extensions and APIs 755
Samples 756
Learning Tools 757
Entity Framework v.Next 757
The Transparent Design Process for the Next Version 758
Blogs, Forums, and Other Resources 758
Appendix: Entity Framework Assemblies and Namespaces . . . . . . . . . . . . . . . . . . . . . . . . . 759
Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 763

  • 24315
  •    605
  • تاریخ ارسال:   1394/07/27

دانلود رایگان کتاب ( PDF )  دانشجویان گرامی اگر این مطلب برای شما مفید بود لطفا ما را در GooglePlus محبوب کنید
رمز عبور: tahlildadeh.com یا www.tahlildadeh.com

لطفا به این مطلب امتیاز دهید
ثبت امتیاز 0
0       0
ارسال دیدگاه نظرات کاربران
شماره موبایل دیدگاه
عنوان پست الکترونیک

ارسال

تمامی حقوق این سایت متعلق به آموزشگاه تحلیل داده می باشد .