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

Programming Entity Framework- DbContext

  • عنوان :

    Programming Entity Framework- DbContext

  • نویسنده : Julia Lerman and Rowan Miller

 

1. Introducing the DbContext API . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
Getting the DbContext API into Your Project 2
Looking at Some Highlights of the DbContext API 3
Reducing and Simplifying Ways to Work with a Set 5
Retrieving an Entity Using ID with DbSet.Find 5
Avoiding Trolling Around the Guts of Entity Framework 6
Working with the BreakAway Model 6
Getting the Sample Solution 6
Getting DbContext from an EDMX Model 8
Ensuring DbContext Instances Get Disposed 11
2. Querying with DbContext . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
Writing Queries with LINQ to Entities 13
Querying All the Data from a Set 16
Using LINQ for Sorting, Filtering, and More 18
Finding a Single Object 21
Querying Local Data 24
Using the Load Method to Bring Data into Memory 26
Running LINQ Queries Against Local 27
Working with the ObservableCollection Returned by Local 29
Loading Related Data 30
Lazy Loading 31
Eager Loading 33
Explicit Loading 36
Checking If a Navigation Property Has Been Loaded 38
Querying Contents of a Collection Navigation Property 39
Explicit Loading a Subset of the Contents of a Navigation Property 41
3. Adding, Changing, and Deleting Entities . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
Working with Single Entities 44
Adding New Entities 44
Changing Existing Entities 45
Deleting Existing Entities 46
Multiple Changes at Once 51
The “Find or Add” Pattern 52
Working with Relationships 53
Adding a Relationship Between Objects 54
Changing a Relationship Between Objects 56
Removing a Relationship Between Objects 57
Working with Change Tracking 59
Using Snapshot Change Tracking 60
Understanding When Automatic Change Detection Occurs 60
Controlling When DetectChanges Is Called 60
Using DetectChanges to Trigger Relationship Fix-up 63
Enabling and Working with Change Tracking Proxies 64
Ensuring the New Instances Get Proxies 67
Creating Proxy Instances for Derived Types 68
Fetching Entities Without Change Tracking 69
4. Working with Disconnected Entities Including N-Tier Applications . . . . . . . . . . . . . 71
A Simple Operation on a Disconnected Graph 72
Exploring the Challenges of N-Tier 74
Using Existing N-Tier Frameworks That Support Graph Modification 76
Using Explicit Operations on the Server Side 77
Replaying Changes on the Server 77
Understanding How DbContext Responds to Setting the State of a Single
Entity 78
Marking a New Entity as Added 79
Marking an Existing Entity as Unchanged 80
Marking an Existing Entity as Modified 81
Registering an Existing Entity for Deletion 83
Working with Relationships with and Without Foreign Keys 85
Setting the State for Multiple Entities in an Entity Graph 88
Getting the Graph into the Context 88
Setting the State of Entities in a Graph 90
Building a Generic Approach to Track State Locally 92
Creating a Generic Method That Can Apply State Through Any Graph 96
Concurrency Implications 98
Tracking Individually Modified Properties 99
Recording Modified Property Names 99
Recording Original Values 102
5. Change Tracker API . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111
Change Tracking Information and Operations for a Single Entity 111
Working with the State Property 112
Working with Current, Original, and Database Values 113
Working with DbPropertyValues for Complex Types 119
Copying the Values from DbPropertyValues into an Entity 122
Changing Values in a DbPropertyValues 123
Working with Individual Properties 128
Working with Scalar Properties 128
Working with Complex Properties 131
Working with Navigation Properties 133
Refreshing an Entity from the Database 137
Change Tracking Information and Operations for Multiple Entities 139
Using the Change Tracker API in Application Scenarios 141
Resolving Concurrency Conflicts 141
Logging During Save Changes 147
6. Validating with the Validation API . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 153
Defining and Triggering Validation: An Overview 154
Validating a Single Object on Demand with GetValidationResult 155
Specifying Property Rules with ValidationAttribute Data Annotations 157
Validating Facets Configured with the Fluent API 158
Validating Unmapped or “Transient” Properties 158
Validating Complex Types 159
Using Data Annotations with an EDMX Model 159
Inspecting Validation Result Details 160
Inspecting Individual Validation Errors 161
Exploring More ValidationAttributes 163
Using CustomValidationAttributes 164
Validating Individual Properties on Demand 166
Specifying Type-Level Validation Rules 166
Using IValidatableObject for Type Validation 167
Validating Multiple Rules in IValidatableObject 169
Using CustomValidationAttributes for Type Validation 171
Understanding How EF Combines Validations 173
Validating Multiple Objects 175
Validating When Saving Changes 178
Reviewing ObjectContext. SaveChanges Workflow 179
Understanding DbContext.SaveChanges Workflow 179
Disabling Validate Before Save 182
7. Customizing Validations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 183
Overriding ValidateEntity in the DbContext 183
Considering Different Ways to Leverage ValidateEntity 187
Updating Data During SaveChanges 192
Overriding SaveChanges When Validation Occurs 193
Comparing ValidateEntity to SaveChanges for Custom Logic 197
Using the IDictionary Parameter of ValidateEntity 198
Controlling Which Entities Are Validated in ValidateEntity 200
8. Using DbContext in Advanced Scenarios . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 203
Moving Between ObjectContext and DbContext 203
Accessing ObjectContext Features from a DbContext 204
Adding DbContext into Existing .NET 4 Applications 205
Leveraging SQL Server Operators Exposed in SqlFunctions 208
Querying Derived Types with DbSet 209
Understanding the Interface Property Limitation 210
Considering Automated Testing with DbContext 210
Testing with DbSet 211
Exploring a Scenario That Unnecessarily Queries the Database 212
Reducing Database Hits in Testing with IDbSet 214
Creating an IDbSet Implementation 214
Abstracting BreakAwayContext for Tests 217
Reviewing the Implementation 221
Supplying Data to a FakeDbSet 221
Accessing the Database Directly from DbContext 222
Executing Queries with Database.SqlQuery and DbSet.SqlQuery 223
Tracking Results of SqlQuery 226
Executing Commands from the Database Class 226
Providing Multiple Targeted Contexts in Your Application 227
Reusing Classes, Configurations, and Validation Across Multiple
Contexts 227
Ensuring That All DbContexts Use a Single Database 231
Validating Relationship Constraints and Other Validations with Multiple
Contexts 232
Getting Code First to Create Full BreakAwayContext Database 232
9. What’s Coming Next for Entity Framework . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 235
Understanding Entity Framework’s Version Numbers 235
Entity Framework 5.0 236
Enums 236
Spatial Data 236
Performance Improvements 236
Multiple Result Sets from Stored Procedures 237
  • 22851
  •    510
  • تاریخ ارسال:   1394/07/27

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

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

ارسال

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