Programming Entity Framework 翻译(1)-目录

时间:2023-01-02 16:24:53

1. Introducing the ADO.NET Entity Framework

ado.net entity framework 介绍 1

The Entity Relationship Model: Programming Against a Model,Not the Database

实体关系模型:使用模型编程,而非数据库 2

The Entity Data Model: A Client-Side Data Model

试题对象模型:客户端对象模型 3

Entities: Blueprints for Business Classes 6

实体:商业类蓝图

The Backend Database: Your Choice 7

后台数据库:你的选择

Database Providers 8

数据库提供者

Access and ODBC 9

Access和 odbc

Entity Framework Features: APIs and Tools 9

Ef 特性:APIS 和工具

Metadata 10

元数据

Entity Data Model Design Tools 10

实体模型设计工具

Object Services 11

Object Services

POCO Support 12

POCO 支持

Change Tracking 12

修改追踪

Relationship Management and Foreign Keys 13

关系管理和外键

Data Binding 13

数据绑定

n-Tier Development 14

N层开发

EntityClient 14

实体客户端

The Entity Framework and WCF Services 15

EF 和 WCF服务

What About ADO.NET DataSets and LINQ to SQL? 15

Ado.net 数据集 和 LINQ to sql 怎么样

DataSets 15

数据集

LINQ to SQL 16

Linq to sql

Entity Framework Pain Points Are Fading Away 16

实体框架不足之处正在减少

Programming the Entity Framework 17

使用EF编程

2. Exploring the Entity Data Model 19

探究实体对象模型

Why Use an Entity Data Model? 19

为什么使用实体对象模型

iii

Download from Library of Wow! eBook <www.wowebook.com>

The EDM Within the Entity Framework 20

EF中的EDM

Walkthrough: Building Your First EDM 21

建立第一个EFM

Inspecting the EDM in the Designer Window 24

在设计窗体中检验EDM

Entity Container Properties 26

实体容器 属性

Entity Properties 26

实体属性

Entity Property Properties 27

实体属性的属性

The Model’s Supporting Metadata 29

模型支持的元数据

Viewing the Model in the Model Browser 31

在模型浏览器中查看模型

Viewing the Model’s Raw XML 31

查看模型规则XML

CSDL: The Conceptual Schema 33

CSDL:概念模型

EntityContainer 34

实体容器

EntitySet 35

实体集合

EntityType 36

实体类型

Associations 38

关系

Navigation Property 41

导航属性

Navigation Properties That Return Collections 42

集合类型的导航属性

SSDL: The Store Schema 43

SSDL:存储模型

MSL: The Mappings 45

MSL:映射

Database Views in the EDM 46

EDM中的数据库视图

Summary 47

汇总

3. Querying Entity Data Models  49

查询实体数据模型

Query the Model, Not the Database 49

查询模型,而非数据库

Your First EDM Query 50

第一个EDM查询

Where Did the Context and Classes Come From? 51

上下文和类的来源

Querying with LINQ to Entities 55

使用linq查询实体

Writing Your First LINQ to Entities Query 55

编写第一个使用linq查询实体代码

Querying with Object Services and Entity SQL 57

使用Object Serveices和 Entity Sql查询

Why Another Way to Query? 57

为何使用其他方式查询

Entity SQL 58

Entity Sql

The Parameterized ObjectQuery 60

参数化的对象查询

Querying with Methods 61

使用方法查询

Querying with LINQ Methods 61

使用linq 方法查询

Querying with Query Builder Methods and Entity SQL 64

使用 query Builder方法和 entity sql 查询

The Shortest Query 66

最简短的查询

ObjectQuery, ObjectSet, and LINQ to Entities 66

Querying with EntityClient to Return Streamed Data 68

使用EntityClient查询返回流数据

EntityConnection and the Connection String 70

EntityConnection 和 连接字符串

EntityCommand 71

ExecuteReader 71

Forward-Only Access to the Fields 71

前进式访问Fileds

Translating Entity Queries to Database Queries 71

将实体查询转换 为数据库查询

Pay Attention to the .NET Method’s Impact on Generated SQL 72

关注。Net 方法对生成的sql的影响

iv | Table of Contents

Download from Library of Wow! eBook <www.wowebook.com>

Avoiding Inadvertent Query Execution 74

避免忽略查询执行

Summary 75

总结

4. Exploring LINQ to Entities in Greater Depth  77

深入探索 linq to entities

Getting Ready with Some New Lingo 78

引入一些新术语做准备

Projections in Queries 78

查询转换

Projections in LINQ to Entities 79

Linq 查询实体的转换

VB and C# Syntax Differences 79

Vb 和 c#的语法却别

LINQ Projections and Special Language Features 80

Linq转换和专有语言特点

Projections with LINQ Query Methods 84

linq 查询方法转换

Using Navigations in Queries 84

在查询中使用导航

Navigating to an EntityReference 84

导航实体引用

Filtering and Sorting with an EntityReference 86

对实体引用进行过滤和排序

Navigating to Entity Collections 86

导航到实体集合

Projecting Properties from EntityCollection Entities 87

实体集合中的实体属性的转换

Filtering and Sorting with EntityCollections 88

对实体集合进行过滤和排序

Aggregates with EntityCollections 88

实体集合的聚集

Aggregates in LINQ Methods 89

Linq方法的聚集

Joins and Nested Queries 90

连接和嵌套查询

Joins 90

连接

Nested Queries 91

嵌套查询

Grouping 93

分组

Naming Properties When Grouping 94

分组时命名属性

Chaining Aggregates 95

束缚聚集??

Filtering on Group Conditions 95

分组条件中过滤

Shaping Data Returned by Queries 97

塑造查询返回数据

Limiting Which Related Data Is Returned 99

限制有关联的数据的返回

Loading Related Data 100

加载关联数据

Controlling Lazy Loading 101

控制延迟加载

Explicitly Loading Entity Collections and Entity References 101

显式加载实体集合和实体引用

Using the Include Method to Eager-Load 103

使用liclude方法进行预先加载

Pros and Cons of Load and Include 106

加载和包含的利弊

Retrieving a Single Entity 107

检索单个实体

Retrieving a Single Entity with GetObjectByKey 108

用 GetObjcetByKey检索单个实体

Finding More Query Samples 109

寻找更多的查询实例

Summary 109

总结

5. Exploring Entity SQL in Greater Depth  111

深入探索entity sql

Literals in Entity SQL 111

Entity sql中的字面量

Expressing a DateTime Literal 112

表达DateTime字面量

Expressing a Decimal Literal 112

表达 Decimal字面量

Using Additional Literal Types 112

使用附加字面量类型

Projecting in Entity SQL 113

Entity sql的转换(投影)

Table of Contents | v

Download from Library of Wow! eBook <www.wowebook.com>

DbDataRecords and Nonscalar Properties 114

Projecting with Query Builder Methods 115

Query Builder方法的转换

Using Navigation in Entity SQL Queries 115

在entity sql 查询中使用导航

Navigating to an EntityReference 115

导航到一个实体引用

Filtering and Sorting with an EntityReference 116

针对实体引用进行过滤和排序

Filtering and Sorting with EntityCollections 116

针对实体集合进行过滤和排序

Aggregating with EntityCollections 117

使用实体集合进行聚集

Using Entity SQL SET Operators 117

使用 entity sql 集合操作

Aggregating with Query Builder Methods 118

使用 query builder 方法聚集

Using Joins 118

使用连接

Nesting Queries 119

嵌套查询

Grouping in Entity SQL 120

在entity sql中进行分组

Returning Entities from an Entity SQL GROUP BY Query 121

Entity sql group by查询返回实体

Filtering Based on Group Properties 121

在分组属性上过滤

Shaping Data with Entity SQL 122

使用entity sql 塑造数据

Using Include with an ObjectQuery and Entity SQL 123

ObjectQuery 和 entirysql 中使用 include

Understanding Entity SQL’s Wrapped and Unwrapped Results 124

理解entiry sql 的打包和非打包结果

Entity SQL Rules for Wrapped and Unwrapped Results 126

Entiry sql 针对打包和非打包结果的规则

Digging a Little Deeper into EntityClient’s Results 126

深入挖掘 EntityClient 的结果

Summary 127

总结

6. Modifying Entities and Saving Changes 129

修改实体并保存更改

Keeping Track of Entities 129

保持实体的追踪

Managing an Entity’s State 130

管理实体的状态

Saving Changes Back to the Database 131

将修改保存到数据库中

Inserting New Objects 134

插入新对象

Inserting New Parents and Children 135

插入新的父类和子类

Deleting Entities 137

删除实体

Summary 139

总结

7. Using Stored Procedures with the EDM  141

在EDM中使用存储过程

Updating the Model from a Database 142

从数据库中更新模型

Working with Functions 143

使用方法

Function Attributes 144

方法属性

Mapping Functions to Entities 146

映射方法和实体

Mapping Insert, Update, and Delete Functions to an Entity 148

映射插入更新和删除方法到实体中

Inspecting Mappings in XML 152

在XML中检查映射

Using Mapped Functions 153

使用映射的方法

Using the EDM Designer Model Browser to Import Additional

使用EDM 模型设计浏览器导入扩展

Functions into Your Model 155

模型中加入方法

Mapping the First of the Read Stored Procedures: ContactsbyState 156

映射首个读取类型的存储过程:ContactsbyState

Using Imported Functions 158

使用导入的方法

Avoiding Inadvertent Client-Side Processing 159

避免忽略客户端处理

vi | Table of Contents

Download from Library of Wow! eBook <www.wowebook.com>

Mapping a Function to a Scalar Type 159

映射方法到一个标量类型

Mapping a Function to a Complex Type 160

映射方法到一个复合类型

Summary 163

8. Implementing a More Real-World Model  165

实现一个更真实的模型

Introducing the BreakAway Geek Adventures Business Model and Legacy Database 166

介绍 the BreakAway Geek Adventures Business 的模型和遗留数据库

Creating a Separate Project for an EDM 168

在EDM中创建一个分支项目

Inspecting and Cleaning Up a New EDM 168

检查并清理一个新的EDM

Modifying the Names of Entities and Properties 170

修改实体的名称和属性

Resolving Collisions Between Property Names and Entity Names 172

解决实体名称和属性名称之间的复数矛盾

Cleaning Up Navigation Property Names 172

清理导航属性名称

Setting Default Values 174

设置默认值

Mapping Stored Procedures 175

配置存储过程

Using the Use Original Value Checkbox in Update Mappings 176

使用“使用原有值”的复选框在更新映射中

Working with Many-to-Many Relationships 178

使用多对多的关系

Inspecting the Completed BreakAway Model 181

检查完整的 BreakAway 模型

Building the BreakAway Model Assembly 182

构建 BreakAway 模型组合

Looking at the Compiled Assembly 183

观看 编译后的组合

Splitting Out the Model’s Metadata Files 184

分离模型的元数据文件

Summary 185

总结

9. Data Binding with Windows Forms and WPF Applications  187

在Windows Forms and WPF 应用程序中进行数据绑定

Data Binding with Windows Forms Applications 187

Windows Forms 程序中的数据绑定

Creating a Windows Forms Application 188

创建Windows Forms 应用程序

Using Windows Forms Data Sources 189

使用 Windows Forms 数据源

Creating an Object Data Source for a Customer Entity 190

为Customer(顾客)实体创建一个 Object Data Source

Getting an Entity’s Details onto a Form 191

获取实体的细节并展示在Form中

Adding Code to Query an EDM When a Form Loads 194

当Form加载事件中添加查看EDM的代码

Binding Without a BindingSource 196

不适用BindingSource 绑定数据

Adding an EntityCollection to the Form 198

在窗体中加入实体集合

Displaying the Properties of Related Data in the Grid 199

在gird中显示相关数据的属性

Allowing Users to Edit Data 201

允许用户修改数据

Editing Navigation Properties (and Shrinking the Query) 202

编辑导航属性

Replacing the Navigation Property TextBoxes with ComboBoxes 204

替换导航属性从文本框修改为复选框

Adding New Customers 208

增加新顾客

Deleting Reservations 211

删除预定(订阅,订房)

Data Binding with WPF Applications 213

WPF应用程序中使用数据绑定

Creating the WPF Form 213

创建wpf窗体

Creating the WPF Project 214

创建wpf项目

Adding the Necessary Data Source Objects 215

增加必要的Data Source Objects

Inspecting the XAML and Code Generated by the Automated

检查自动生成的XAML和代码

Data Binding 215

数据绑定

Table of Contents | vii

Download from Library of Wow! eBook <www.wowebook.com>

Adding Code to Query the EDM When the Window Loads 216

在窗体加载事件中添加查询EDM的代码

Customizing the Display of the Controls 218

定制显示控件

Selecting an Entity and Viewing Its Details 219

选择一个实体并展示其明细

Adding Another EntityCollection to the Mix 222

增加其他的实体集合到Mix

Editing Entities and Their Related Data 224

编辑实体和他们的关联数据

Using Sort Descriptions to Keep Sorting in Sync with Data Modifications225

使用排序描述在修改数据的时候同步执行排序

Adding Items to the Child EntityCollection 226

在子集合中增加元素

The Last Task: Adding New Trips to the Catalog 227

最后的工作:目录中增加新的协定

Summary 230

总结

10. Working with Object Services  231

使用object serveices

Where Does Object Services Fit into the Framework? 231

在framework中object services 的立足支出?

Processing Queries 233

处理查询

Parsing Queries: From Query to Command Tree to SQL 234

解析查询:query-》命令树-》sql

Understanding Query Builder Methods 235

理解 Query Builder 方法

Analyzing a Query with ObjectQuery Methods and Properties 238

使用 ObjectQuery 的方法和属性分析查询

Executing Queries with ToList, ToArray, First or Single 241

使用ToList, ToArray, First or Single进行查询

Executing Queries with the Execute Method 242

使用Execute方法执行查询

Overriding a Default Connection with ObjectContext.Connection 242

使用ObjectContext.Connection重载默认连接

Handling Command Execution with EntityClient 244

掌握EntityClient中的 Command 执行

Materializing Objects 244

物化对象

Managing Object State 246

管理对象状态

Using EntityKey to Manage Objects 246

使用EntityKey来管理对象

Merging Results into the Cache with MergeOptions 247

使用MergeOptions来讲结果合并到缓存中。

Inspecting ObjectStateEntry 248

查看ObjectStateEntry

Maintaining EntityState 249

维护EntityState

Managing Relationships 252

管理关系

Attaching and Detaching Objects from the ObjectContext 253

ObjectContext中附加和分离对象

Taking Control of ObjectState 257

掌控ObjectState

ObjectStateManager Methods 257

ObjectStateManager 的方法

ObjectStateEntry State Methods for Managing State 258

ObjectStateEntry 中管理状态的状态方法

ObjectSet State Methods 259

ObjectSet 状态方法

Sending Changes Back to the Database 259

将变化发送给数据库

ObjectContext.SaveChanges 259

Affecting SaveChanges Default Behavior 260

影响SaveChanges的违约行为

Overriding SaveChanges Completely 261

完全重写SaveChanges

Data Validation with the SavingChanges Event 261

SavingChanges 时间中校验数据

Concurrency Management 261

并发管理

Transaction Support 262

事务支持

Implementing Serialization, Data Binding, and More 263

实现,序列化,数据绑定,等等

Object Services Supports XML and Binary Serialization 263

Object Services 支持xml和二进制的序列化

Object Services Supports Data Binding 265

Object Services 支持数据绑定

viii | Table of Contents

Download from Library of Wow! eBook <www.wowebook.com>

Summary 266

11. Customizing Entities  267

定制实体

Partial Classes 267

分布类

Using Partial Methods 269

使用分布方法

The OnContextCreated Method 269

OnContextCreated 方法

The On[Property]Changed and On[Property]Changing Methods 271

On[Property]Changed 和 On[Property]Changing 方法

Using PropertyChanged to Calculate Database-Computed Columns

使用 PropertyChanged 来计算数据库计算列

Locally 273

本地化

Subscribing to Event Handlers 274

订阅事件句柄

The ObjectContext.ObjectMaterialized Event 275

ObjectContext.ObjectMaterialized 事件

The ObjectContext.SavingChanges Event 276

ObjectContext.SavingChanges 事件

The EntityObject.PropertyChanging and EntityObject.PropertyChanged Events 280

EntityObject.PropertyChanging 和 EntityObject.PropertyChanged 事件 280

The AssociationChanged Event 282

AssociationChanged事件

Creating Your Own Partial Methods and Properties 284

创建分布方法和属性

Overriding the Object Constructor 284

重载 Object 构造器

Overriding ObjectContext.SaveChanges 285

重载 ObjectContext.SaveChanges 285

Creating Custom Properties 286

创建自定义属性

Overloading Entity Creation Methods 289

重载 实体创建方法

Using Partial Classes for More Than Just Overriding Methods and Events 290

使用分布类而不只是重载方法和事件

Overriding Default Code Generation 291

重载默认的代码生成

Switching to a Template 292

选择模板

Reading the Template 292

读取模板

Modifying the Template 293

修改模板

Customizing a Template for Major Class Modifications 295

为主要类的变动定制模板

Switching Between the Default Template and a Custom Template 295

在默认模板和定制模板间切换选择

Summary 296

总结

12. Data Binding with RAD ASP.NET Applications 297

Using the EntityDataSource Control to Access Flat Data 298

使用EntityDataSource空间访问平数据

Creating the Hello Entities Project 298

创建 Hello entitys 项目

Creating a GridView and an EntityDataSource Concurrently 299

同步创建 GridView和EntityDataSouce

Configuring an EntityDataSource with Its Wizard 299

使用向导配置EntityDataSouce

Formatting the GridView 301

格式化GridView

Testing the Web Application 303

测试web程序

Understanding How the EntityDataSource Retrieves and Updates Your Data 304

理解EntityDataSouce如何去获取和更新数据

EntityDataSource and Its Query 304

EntityDataSource的查询

EntityDataSource and Its ObjectContext 305

EntityDataSource的ObjectContext

EntityDataSource Context Events 306

EntityDataSource 上线文事件

EntityDataSource and ViewState 306

EntityDataSource视图状态

Accessing Foreign Keys When There Is No Foreign Key Property 308

没有外键属性的情况下访问外键

Working with Related EntityReference Data 309

使用实体引用数据

Using EntityDataSource.Include to Get Related Data 309

使用EntityDataSource.Include获取关联数据

Displaying Data That Comes from EntityReference

显示实体引用的数据

Navigation Properties 310

导航属性

Using a New EntityDataSource Control to Enable Editing of EntityReference Navigation Properties 312

使用一个新EntityDataSource控件来启用编辑实体导航属性

Editing EntityReferences That Cannot Be Satisfied with a Drop-Down List 313

编辑无法适用于下拉列表的实体引用

Binding an EntityDataSource to Another Control with Where Parameters 314

使用 where 参数将 EntityDataSource 和其他控件绑定

Editing Related Data Concurrently with Multiple EntityDataSource Controls 316

使用复合EntityDataSource控件同步编辑有关联数据

Working with Hierarchical Data in a Master/Detail Form 317

在主子窗体中使用分层数据

Setting Up the Web Application 317

建立web程序

Specifying Your Own Entity SQL Query Expression for an EntityDataSource 318

给 EntityDataSource 指定Entity Sql 查询表达式

Binding a DropDownList to an EntityDataSource Control 319

将一个下拉列表绑定到 EntityDataSource 控件

Creating a Parent EntityDataSource That Is Controlled  by the DropDownList and Provides Data to a DetailsView 320

创建一个已被下拉列表控制的父 EntityDataSource,并给明细视图提供数据.

Using the EntityDataSource.Where Property to Filter Query Results 321

使用 EntityDataSource的where 属性 来过滤查询结果

Displaying Read-Only Child Data Through the Parent EntityDataSource 321

通过父级 EntityDataSource 来展示只读子级数据

Using a New EntityDataSource to Add a Third Level of Hierarchical

Data to the Master/Detail Form 323

在主子窗体中新增一个EntityDataSource 来达到3层关系

Using the EntityDataSource.Inserting Event to Help with Newly

Added Entities 325

使用EntityDataSource.Inserting 事件来操作新增实体

Testing the Application 326

测试程序

Exploring EntityDataSource Events 327

探索 EntityDataSource事件

Building Dynamic Data Websites 329

建立动态数据web端

Summary 332

总结

13. Creating and Using POCO Entities  335

13.创建和使用 poco实体

Creating POCO Classes 336

创建poco类

Creating an ObjectContext Class to Manage the POCOs 339

创建ObjectContext类,来管理pocos

Change Tracking with POCOs 341

跟踪Pocos的变化

Understanding the Importance of DetectChanges 341

利息额发现变化的重要性

Loading Related Data with POCOs 341

使用pocos加载关联数据

Loading from the Context 342

从上下文中加载数据

Lazy Loading from a Dynamic Proxy 342

从动态代理中延迟加载数据

Exploring and Correcting POCOs’ Impact on Two-Way Relationships 342

探究并解决poco中的双向依赖冲突

Using the DetectChanges Method to Fix Relationships 343

使用DetectChanges方法调整关系

Enabling Classes to Fix Their Own Relationships 344

启用类的关系

Using Proxies to Enable Change Notification, Lazy Loading, and Relationship Fix-Up345

使用代理来启用改变通知,延迟加载和关系修复

Change Notification by Proxy 346

用代理实现改变通知

Lazy Loading by Proxy 346

用代理实现延迟加载

Exploring the Proxy Classes 347

探究代理类

Synchronizing Relationships by Proxy 348

用代理实现关系同步

Using T4 to Generate POCO Classes 350

使用T4模板生成POCO类

Modifying the POCO Template 354

修改POCO模板

Creating a Model That Works with Preexisting Classes 358

对已存在的类创建模型

Code First: Using Entity Framework with No Model at All 359

Code first EF中不使用模型.

Summary 359

总结

14. Customizing Entity Data Models Using the EDM Designer 361

14使用EDM设计器定制实体数据模型

Mapping Table per Type Inheritance for Tables That Describe Derived Types 362

继承类型的TPT映射

Mapping TPT Inheritance 363

映射TPT继承

Querying Inherited Types 365

查询有继承类型

POCO Classes and Inherited Objects 366

POCO类和继承对象

Inserting TPT Inherited Types 366

插入TPT继承类型

Specifying or Excluding Derived Types in Queries 368

在查询中指定或者排除派生类型

Creating New Derived Entities When the Base Entity Already Exists 370

根据已有的基类实体创建派生实体

TPT with Abstract Types 371

用抽象类型实现TPT

Mapping Unique Foreign Keys 373

映射唯一的外键

Mapping an Entity to More Than One Table 375

将多表映射到一个实体中

Merging Multiple Entities into One 376

将多个实体映射到一个表中

Querying, Editing, and Saving a Split Entity 378

查询编辑和保存一个分割的实体

Mapping Stored Procedures to Split Tables and More 380

映射存储过程到拆分表中

Splitting a Single Table into Multiple Entities 381

将一个表拆分到多个实体中

Filtering Entities with Conditional Mapping 383

根据条件映射配置过滤实体

Creating a Conditional Mapping for the Activity Entity 385

给活动实体创建一个条件式映射.

Querying, Inserting, and Saving with Conditional Mappings 385

查询,插入,和保存条件式映射

Filtering on Other Types of Conditions 387

使用其他类型的条件过滤

Removing the Conditional Mapping from Activity and Re-creating the Category Property 388

从活动类型移除条件式映射并重建类型属性

Implementing Table per Hierarchy Inheritance for Tables That Contain Multiple Types 389

实现TPH

Creating the Resort Derived Type 390

创建Resort派生类型

Setting a Default (Computed) Value on the Table Schema 391

在表模型中设置默认(推算)值

Testing the TPH Mapping 392

测试TPH映射

Choosing to Turn a Base Class into an Abstract Class 393

选择将基类转换为抽象类

Creating Complex Types to Encapsulate Sets of Properties 393

创建复合类型来封装一些属性

Defining a Complex Type 394

顶一个复合类型

Reusing Complex Types 396

重用复合类型

Querying, Creating, and Saving Entities That Contain Complex Types 397

查询,创建和保存包含复合类型的实体

Removing the Complex Types from the Model 398

从模型中移除复合类型

Using Additional Customization Options 399

使用扩展定制选项

Using GUIDs for EntityKeys 399

永GUIDS作为实体键

Mapping Stored Procedures 399

映射存储过程

Mapping Multiple Entity Sets per Type 399

映射同类型的多个实体集合

Mapping Self-Referencing Associations 400

映射自引用

Summary 401

总结

15. Defining EDM Mappings That Are Not Supported by the Designer 403

定义设计器不支持的EDM映射

Using Model-Defined Functions 403

使用 模型预定义函数

Using Model-Defined Functions to Return More Complex Results 407

使用模型预定义函数来返回更多的复合结果

Consuming the Complex Results 408

定制复合结果

Reading the Results from a Complex Function 408

从复合函数中读取结果

Mapping Table per Concrete (TPC) Type Inheritance for Tables with Overlapping Fields 409

映射TPC

Using QueryView to Create Read-Only Entities and Other Specialized Mappings 411

使用查询视图创建只读实体和其他指定的映射

Finding a Common Use Case for QueryView 413

为查询视图的寻找一个常规用例.

Creating a CustomerNameAndID Entity 413

创建一个顾客实体,包含名称和ID属性

Creating a QueryView Mapping for CustomerNameAndID 414

为顾客创建查询视图映射

Testing the QueryView 416

测试查询视图

Deconstructing the QueryView 416

析构查询视图

Summary 417

总结

16. Gaining Additional Stored Procedure and View Support in the Raw XML 419

从规则XML中过去扩展存储过程和视图支持

Reviewing Procedures, Views, and UDFs in the EDM 419

回顾EDM中的过程,视图,和自定义函数

Working with Stored Procedures That Return Data 420

使用存储过程返回数据

Using Functions That Match an Entity Whose Property Names Have Been Changed 420

使用函数来适应一个实体的属性名称被修改

Query Stored Procedures and Inherited Types 421

查询存储过程和继承类型

Composing Queries Against Functions 423

对函数使用组合查询

Replacing Stored Procedures with Views for Composability 423

为满足可组合型,使用视图来替换存储过程

Queries That Return Multiple Result Sets 424

查询多结果集的返回

Executing Queries on Demand with ExecuteStoreQuery 424

对ExecuteStoreQuery的需求执行查询

Querying to a Class That Is Not an Entity 424

查询非实体的类

Querying into an Entity 425

将实体作为查询结果

Adding Native Queries to the Model 426

增加模型的本地查询

Defining a Complex Type in the Model Browser 427

在模型浏览器中定义复合类型

Adding Native Views to the Model 429

给模型增加本地视图

DefiningQuery Is Already in Your Model 429

模型中已存在DefiningQuery

Using DefiningQuery to Create Your Own Views 431

使用DefiningQuery来创建视图

Implementing a DefiningQuery 433

实现DefiningQuery

Creating Associations with the New Entity 437

给新实体创建关联

Using DefiningQuery to Solve More Complex Problems 438

使用 DefiningQuery 来解决更多的复合问题

Using Commands That Affect the Database 440

使用commands操作上胡句酷

Executing SQL on the Fly with ExecuteStoreCommand 440

运行时使用ExecuteStoreCommand执行 sql

Using Functions to Manipulate Data in the Database 441

使用函数操作数据库中的数据

Mapping Insert/Update/Delete to Types Within an Inheritance Structure 444

为继承性结构类型来映射插入,更新,删除

What If Stored Procedures Affect Multiple Entities in an Inheritance

Structure? 445

如果存储过程影响了继承性结构的多实体,会怎么样

Implementing and Querying with User-Defined Functions (UDFs) 445

使用UDFs实现和查询.

Summary 447

总结

17. Using EntityObjects in WCF Services 449

17.在WCF服务中使用实体对象

Planning for an Entity Framework–Agnostic Client 450

为未知的客户端规划EF

Assessing the Pros and Cons of an Entity Framework–Agnostic

Consumer 451

为未知用户综合评估EF

Building a Simple WCF Service with EntityObjects 452

使用EntityObjects 创建一个简单的WCF服务.

Creating the Service 453

创建服务

Defining the Service Operations 454

定义服务选项

Defining Extra Service Classes 455

定义附加服务类

Exposing Custom Properties 456

曝光定制属性

Implementing the Service Interface 457

实现服务接口

Adding Graphs to ObjectContext 460

给ObjectContext增加数据图

Deleting Objects 461

删除对象

Updating the Object Graph 463

删除对象图

Client Rules for Identifying Changes in an EntityCollection 463

控制实体集合中变化的客户端规则

The UpdateCustomer Method 463

更新客户的方法

Handling New and Existing Reservations 465

处理新增和已存在的预定

Deleting Reservations 466

删除预定

Building a Simple Console App to Consume an EntityObject Service 467

创建简单的控制台程序来调用EntityObject Service

Enabling the Client Application to Receive Large Messages from the Service 468

让客户端程序来接收服务的大量消息

Creating Methods to Test the Service Operations 469

创建方法来测试服务选项

Analyzing the GetAndUpdateCustomer Method 473

解析GetAndUpdateCustomer 方法

Testing Out the Other Service Operations 474

测试其他的服务选项

Creating WCF Data Services with Entities 474

使用实体创建WCF数据服务

Putting WCF Data Services in Perspective 475

透明的投掷wcf数据服务.

Creating a WCF Data Service 475

创建WCF数据服务

Filtering at the Service Level Using QueryInterceptor 480

使用查询拦截器过滤服务层

Anticipating Exceptions 481

应用程序的异常

Exposing Related Data Through the Service 481

在服务中曝光关联数据

Preparing for WCF Data Services’ Limitations 483

为WCF数据服务的限制做准备

Modifying Data Through a Service 484

通过服务修改数据

Learning More About Creating and Consuming WCF Data Services 485

学习更多关于创建和调用WCF数据服务.

Table of Contents | xiii

Download from Library of Wow! eBook <www.wowebook.com>

Understanding How WCF RIA Services Relates to the Entity Framework 485

理解WCF RIA Services如何关联到EF

Summary 487

总结

18. Using POCOs and Self-Tracking Entities in WCF Services  489

18.WCF服务中使用POCOS和自跟踪实体

Creating WCF-Friendly POCO Classes 490

创建WCF-Friendly的POCO类

Updating the POCO Classes Based on the Current BreakAway Model 490

基于当前分离模型中更新POCO类

Isolating the POCO Entities in Their Own Project 491

将poco实体分离到独立的项目中

Adding Custom Logic to the POCO Entities with a Base Class 493

使用poco实体的基类,增加定制逻辑

Following WCF Collection Rules 495

遵守wcf集合规则

Preventing Properties from Being Marked As Virtual 496

防止属性被标识为virtual

Building a WCF Service That Uses POCO Classes 497

使用POCO类,建立WCF服务

Implementing the Interface 498

实现接口

Using the Service 500

使用服务

Using the Self-Tracking Entities Template for WCF Services 503

为WCF服务使用自跟踪实体模板

Creating and Exploring the Self-Tracking Entities 503

创建并探究自跟踪实体

Putting the Change-Tracking Logic Where It’s Needed 505

在需要的地方投递改变追踪逻辑

Creating a WCF Service That Uses Self-Tracking Entities 506

使用自跟踪实体创建WCF服务

Watching Self-Tracking Entities Under the Covers 507

揭秘自跟踪实体

Inspecting the Generated Context Class and Extensions 513

审查生成的上下文和扩展

Using POCO Entities with WCF Data and RIA Services 515

Wcf data 和ria services中使用poco实体

Preparing for WCF Data Services 515

准备wcf数据服务

Using POCO Entities in WCF RIA Services 517

在wcf ria services中使用poco实体

Sorting Out the Many Options for Creating Services 519

清理many 选项来创建服务

Summary 520

总结

19. Working with Relationships and Associations 521

使用依赖和关联

Deconstructing Relationships in the Entity Data Model 522

解构实体数据模型中的依赖

Understanding How the Entity Data Model Wizard Creates the Association 523

理解实体数据模型向导的创建关联

Understanding Additional Relationship Items 525

理解扩展以来节点

Handling Nonessential Navigation Properties 526

处理费必要导航属性

Understanding the Major Differences Between Foreign Key Associations and Independent Associations 527

理解外键关联和实现关联之间的区别

Defining Associations in Metadata 528

在元数据中定义关联

Detecting Associations at Runtime 528

运行时检测关联

Deconstructing Relationships Between Instantiated Entities 529

解构实例化的实体之间的依赖

Understanding Relationship Manager and the IRelatedEnd Interface 530

理解依赖管理器和IRelatedEnd接口

Late-Binding Relationships 530

迟绑定依赖

Taking a Peek Under the Covers: How Entity Framework Manages Relationships 531

揭秘:EF如何管理依赖

Understanding Navigation Properties 534

理解导航属性

Understanding Referential Integrity and Constraints 537

理解引用完整性和约束

Implementing Deletes and Cascading Deletes 540

实现删除和级联删除

Defining Relationships Between Entities 542

定义实体之间的依赖

The CLR Way: Setting a Navigation Property to an Entity 543

CLR 方式:设置实体的导航属性

Setting a Foreign Key Property 544

设置外键属性

Setting an EntityReference Using an EntityKey 544

利用EntityKey设置实体引用

Loading, Adding, and Attaching Navigation Properties 545

加载,增加,附加导航属性

Lazy Loading 545

迟加载

EntityReference.Load and EntityCollection.Load 547

EntityReference.Load 和 EntityCollection.Load

Loading from Detached Entities: Lazy and Explicit 547

延迟或者显式加载分离实体.

Using EntityCollection.Add 548

使用EntityCollection.Add

Using Attach and Remove 549

使用附加和移除

Moving an Entity to a New Graph 550

将实体迁移到新的图中

Learning a Few Last Tricks to Make You a Relationship Pro 551

学一些新技巧来处理依赖关系

Using CreateSourceQuery to Enhance Deferred Loading 551

使用CreateSourceQuery来增强延迟加载

Getting a Foreign Key Value in an Independent Association 552

在实现关联中获取外键值

Summary 553

总结

20. Real World Apps: Connections, Transactions, Performance, and More 555

20.真实世界的程序:连接,事务,性能等等

Entity Framework and Connections 555

EF和连接

Overriding EntityConnection Defaults 556

重写默认的EntityConnection

Working with Connection Strings Programmatically 557

以编程方式使用连接字符串

Opening and Closing Connections 560

打开和关闭连接

Getting the Store Connection from EntityConnection 562

从EntityConnection中获取已有的连接

Disposing Connections 562

释放连接

Pooling Connections 563

连接池

Fine-Tuning Transactions 564

微调事务

Why Use Your Own Transaction? 564

为何使用自己的事务

Understanding Implicit Entity Framework Transactions 565

理解EF隐式事务

Specifying Your Own Read/Write Transactions 566

指定自己的读写事务

Specifying Your Own Read-Only Transactions 569

指定自己的只读事务

Rolling Back Transactions 570

回滚事务

Understanding Security 571

理解安全

Guarding Against SQL Injection 571

防止sql注入

Guarding Against Connection Piggybacks 573

防止连接搭载

Fine-Tuning Performance 574

微调性能

Measuring Query Performance 575

测试查询性能

Measuring Startup Performance 579

测试启动性能

Reducing the Cost of Query Compilation 580

减少查询编译的性能消耗

Caching for Entity SQL Queries 580

Entity sql 的查询缓存

Precompiling Views for Performance 582

预编译视图提升性能

Precompiling LINQ to Entities Queries for Performance 585

预编译 linq to entities查询提升性能

Fine-Tuning Updates for Performance? 589

微调更新提升性能

Lacking Support for Full Text Searches 590

缺少全文搜索的支持

Exploiting Multithreaded Applications 591

有效的利用多线程程序

Forcing an ObjectContext to Use Its Own Thread 591

保证让一个objectContext使用它自己的线程

Implementing Concurrent Thread Processing 593

实现并发线程处理

Exploiting .NET 4 Parallel Computing 596

有效的利用.net4的并发处理

Summary 596

总结

21. Manipulating Entities with ObjectStateManager and MetadataWorkspace 597

21.使用objectStat4eManger 和MetadataWorkspace来操控实体

Manipulating Entities and Their State with ObjectStateManager 598

使用ObjectStateManager操控实体以及其状态

Refreshing Your High-Level Understanding of ObjectStateEntry 599

深入理解ObjectStateEntry

Getting an ObjectStateManager and Its Entries 599

获取ObjectStateManager和他的实体

Building Extension Methods to Overload GetObjectStateEntries 600

创建扩展方法来重载 GetObjectStateEntries

Building a Method to Return Managed Entities 602

创建方法来返回 Managed Entities

Using GetObjectStateEntry and TryGetObjectStateEntry 603

使用GetObjectStateEntry 和 TryGetObjectStateEntry

Mining Entity Details from ObjectStateEntry 604

从ObjectStateEntry中挖掘实体细节

Leveraging the ObjectStateManager During Saves 609

保存过程中利用ObjectStateManager

Using ObjectStateManager to Build an EntityState Visualizer 611

使用ObjectStateManager来创建一个实体状态观察期

Retrieving an ObjectStateEntry Using an EntityKey 612

使用实体键获取一个ObjectStateEntry

Reading the OriginalValues and CurrentValues of an ObjectStateEntry 613

读取ObjectStateEntry的旧值和新值

Determining Whether a Property Has Been Modified 614

确定属性是否被修改

Displaying the State and Entity Type 614

显示状态和实体类型

Getting ComplexType Properties Out of ObjectStateEntry 615

从ObjectStateEntry获取复杂类型属性

Modifying Values with ObjectStateManager 619

使用ObjectStateManager修改值

Working with Relationships in ObjectStateManager 620

使用ObjectStateManager的关系

Using the MetadataWorkspace 622

使用MetadataWorkspace

Loading the MetadataWorkspace 622

加载MetadataWorkspace

Clearing the MetadataWorkspace from Memory 623

从内存中清除MetadataWorkspace

Understanding the MetadataWorkspace ItemCollections 624

理解MetadataWorkspace的元素集合

Retrieving Metadata from the MetadataWorkspace 625

从MetadataWorkspace获取元数据

Querying the Metadata with LINQ to Objects 628

使用LINQ to Objects查询元数据

Building Dynamic Queries and Reading Results 629

创建动态查询并读取结果

Building Entity SQL Queries Dynamically Using Metadata 629

使用元数据来动态创建Entity SQL 查询

Creating Queries on the Fly with CreateObjectSet and Query Builder Methods 632

使用CreateObjectSet and Query Builder 方法创建运行时查询

Reading the Results of a Dynamically Created Query 634

读取动态创建查询的结果

Creating and Manipulating Entities Dynamically 637

动态的创建和操控实体

Creating EntityObjects Without Entity Classes 637

不使用实体类创建实体对象

Creating Entities and Graphs Dynamically 640

动态创建实体和数据图

Summary 643

总结

22. Handling Exceptions  645

22.处理异常

Preparing for Exceptions 645

为异常做准备

Handling EntityConnectionString Exceptions 647

处理EntityConnectionString异常

Connection String Can’t Be Found or Is Improperly Configured:System.ArgumentException 648

连接字符串未找到或者不正确的配置: System.ArgumentException

Metadata Files Cannot Be Found: System.Data.MetadataException 648

元数据文件未找到: System.Data.MetadataException

Handling Connection String Exceptions 649

处理连接字符串异常

Handling Query Compilation Exceptions 649

处理查询编译异常

Invalid LINQ to Entities Query Expressions:System.NotSupportedException 649

无效的linq to entities 查询异常:System.NotSupportedException

Invalid Entity SQL Query Expressions: EntitySqlException 650

无效的Entity SQL查询异常: EntitySqlException

EntityCommandCompilationException Thrown by the Store Provider 652

存储提供程序跑出的EntityCommandCompilationException

Creating a Common Wrapper to Handle Query Execution Exceptions 652

创建公共封装来处理查询执行异常

Handling Exceptions Thrown During SaveChanges Command Execution 654

处理SaveChanges 命令执行抛出的异常

UpdateException: Thrown When Independent Association Mapping Constraints Are Broken 654

UpdateException:当独立的关联映射中违背约束时抛出

UpdateException: Thrown by Broken Constraints in the Database 655

UpdateException:违背数据库中的约束时抛出

Relying on Entity Framework to Automatically Roll Back When an UpdateException Occurs 656

当更新异常发生时依赖EF的自动回滚

Gleaning Details from UpdateException 656

回头再看更新异常的详情

Planning for Other Exceptions Related to the Entity Framework 657

为跟EF相关的其他异常做准备

Handling Concurrency Exceptions 658

处理并发异常

Summary 658

总结

23. Planning for Concurrency Problems  659

为并发问题做准备

Understanding Database Concurrency Conflicts 660

理解数据库并发冲突

Understanding Optimistic Concurrency Options in the Entity Framework

660

理解EF中的乐观并发控制

Ignoring Concurrency Conflicts 661

忽略并发冲突

Forcing the User’s Data to the Server (ClientWins) 661

强制用户数据在server端

Refreshing the User’s Data with Server Data (StoreWins) 661

根据服务器端的数据刷新用户数据

Determining the Scope of Changes 662

确定变化的范围

Using rowversion (a.k.a. timestamp) for Concurrency Checks 662

使用行版本并发校验

Implementing Optimistic Concurrency with the Entity Framework 663

使用EF实现乐观并发

Flagging a Property for Concurrency Checking 664

标记一个属性来作为并发检查

How the Entity Framework Uses the ConcurrencyMode Property 665

EF如何使用并发模型属性

Concurrency Checking Without a rowversion Field 666

不使用rowversion字段作并发检查

Concurrency Checking on a Checksum in the Data Store 666

使用数据存储中的校验和检测并发

Concurrency Checks for EntityReference Navigation Properties 667

对实体银行的导航属性做并发检查

Concurrency Checks and Inherited Types 667

继承类型的并发检查

Concurrency Checks and Stored Procedures 668

并发检查和存储过程

Handling OptimisticConcurrencyExceptions 670

处理乐观并发异常

Using ObjectContext.Refresh 671

使用ObjectContext.Refresh

Using Refresh with ClientWins 671

ClientWins使用刷新

Using Refresh with StoreWins 673

StoreWins使用刷新

Refreshing Collections of Entities 673

刷新实体集合

Refreshing Related Entities in a Graph 675

刷新同一数据图中的关联实体

Rewinding and Starting Again, and Maybe Again After That 676

再来一遍,获取以后需要再次面对

Reporting an Exception 678

报告异常

Handling Concurrency Exceptions at a Lower Level 678

低级的并发处理

Handling Exceptions in a Granular Way Without User Intervention 678

用精细的方式处理异常,不用用户干涉

Handling Multiple Conflicts 680

处理多重冲突

Handling Exceptions When Transactions Are Your Own 682

事务中处理异常

Summary 683

总结

24. Building Persistent Ignorant, Testable Applications  685

创建持久透明化和可测试的程序

Testing the BreakAway Application Components 686

测试独立的程序组件

Getting Started with Testing 687

开始测试

Writing an Integration Test That Hits the Database 687

对数据库进行综合测试

Inspecting a Failed Test 689

检查错误的测试

Writing a Unit Test That Focuses on Custom Logic 689

为指定逻辑编写单元测试

Creating Persistent Ignorant Entities 693

穿件持久层透明的实体

Planning the Project Structure 695

准备项目结构

Starting with the Model and Its POCO Entities 697

着手模型和其对应的poco实体

Building an Interface to Represent a Context 698

创建描述上下文的接口

Modifying the BAEntities ObjectContext Class to Implement the New Interface 699

修改 BAEntities ObjectContex 来实现新接口

Creating the IEntityRepository Interface 702

创建 IEntityRepository 接口

Creating the Repository Classes 703

创建Repository类

Testing GetReservationsForCustomer Against the Database 706

针对数据库测试GetReservationsForCustomer

Creating a Fake Context 708

创建模拟上下文

Creating a FakeObjectSet Class 710

创建模拟对象集合类

Completing the Fake Context 712

完成模拟上下文

Building Tests That Do Not Hit the Database 714

创建非命中数据库的测试

Adding Validation Logic to the POCO Class 714

Poco类增加校验逻辑

Adding Validation Logic to the Context 716

上下文增加校验逻辑

Providing ManagedEntities in the FakeContext 716

在模拟上下文中提供ManagedEntities

Hiding the Context from the Lower Layers with Unit of Work 718

单元工作中隐藏底层上下文

Testing UnitOfWork Against the Database 720

针对数据库测试单元工作

Enabling Eager Loading in IContext 721

IContext中启用 Eager Loading

Leveraging Precompiled Queries in Your Repositories 722

仓储中利用预编译查询

Using the New Infrastructure in Your Application 723

在程序中使用新的基础架构

Adding a UI Layer That Calls the Repository 723

增加UI层调用仓储

Application Architecture Benefits from Designing Testable Code 724

设计可测试的程序架构的好处

Considering Mocking Frameworks? 725

考虑Mocking Frameworks

Summary 725

总结

25. Domain-Centric Modeling 727

25.领域为重心的模型

Creating a Model and Database Using Model First 728

使用model first 创建模型和数据库

Creating a Conceptual Model in the Designer 728

设计器中创建概念模型

Creating the Entities 730

创建实体

Creating Association and Inheritance Hierarchies 734

创建关联和继承体系

Generating Database Schema from the Model 738

从模型生成数据库架构

Creating the Database and Its Schema 744

创建数据库和他的架构

Overriding the DDL Generation 745

重写 DDL 生成

Using the Feature CTP Code-First Add-On 747

使用code-first中增加的特性CTP

Understanding Code-First Design 749

理解 code-first设计

Installing the Feature CTP 751

安装CTP特性

Exploring Some Configuration Examples 751

搜索一些配置案例

Testing the Code-First Application and Database 753

测试code-first程序和数据库

Using SQL Server Modeling’s “M” Language 755

使用 sqlserver 模型的M语言

Using M Metadata in Entity Framework Applications 758

在EF程序中使用M元数据

Summary 759

总结

26. Using Entities in Layered Client-Side Applications  761

26.在分层客户端程序中使用实体

Isolating the ObjectContext 762

分离 objectcontext;

Freeing Entities from Change Tracking 764

变化跟踪中释放实体

Enabling Change Tracking Across Tiers 766

层中启用变化跟踪

Moving Other ObjectContext-Dependent Logic to the DataBridge 768

将所依赖其他ObjectContext 逻辑移动到 dataBridge

Ensuring That Lazy Loading Doesn’t Negatively Impact the Layered Application 772

确保延迟加载不会给分层程序造成负面影响

Noting Additional Benefits of the Layered Application 773

注意分层程序的额外好处

Separating Entity-Specific Logic from ObjectContext Logic 774

从objectContext逻辑中分离实体特有的逻辑

Working with POCO Entities 778

使用POCO实体

Providing EntityState 779

提供EntityState

Providing Logic in Place of Other EntityObject Behavior 781

提供逻辑来替换EntityObject的行为

Summary 782

总结

27. Building Layered Web Applications  783

27.建立分层web程序

Understanding How ObjectContext Fits into the Web Page Life Cycle 783

理解ObjectContext如何适应web页面的生命周期

Return Results, Not Queries, from the DataBridge Class 785

返回dataBridge类的非查询结果

Using Entities in Read-Only Web Pages 786

在只读web页中使用实体

Exploring Options for Updating Entities in an ASP.NET Web Forms Application 788

搜索 asp.net web forms中更新实体的选项

Comparing ASP.NET’s State Solutions to the Needs of the Entity Framework 789

将asp.net的状态解决方案做比较来看EF的必要性

Building an N-Tier Web Forms Application 793

创建 n-层web forms程序

Designing the Application 794

设计程序

Using the Existing Repositories 795

使用现有的仓储

Building an Entity Manager to Act As a DataBridge 795

Act中创建实体管理器作为数据桥梁

Retrieving Data for Display and for Future Updates 797

获取数据来显示以及之后的更新

Making the Related Data Accessible to the Client 799

使得关联的数据能够被客户端访问

Getting Data from the Manager to the Client 800

从管理器中获取数据给客户端

Adding Lists for User Selection Controls 803

给用户增加选择控制的列表

Allowing a User to Modify Related Data 805

允许用户修改关联数据

Building an ASP.NET MVC Application 806

创建 一个asp.net mvc程序

Replacing the Context with Repositories 813

使用仓储来替换上下文

Editing Entities and Graphs on an MVC Application 814

在MVC程序中编辑实体和数据图

Creating a Repository for Payments 817

创建仓储作为提供者

Interacting with the ReservationController 817

使用预定控制器

Summary 818

总结

A. Entity Framework Assemblies and Namespaces  821

B. Data-Binding with Complex Types  825

C. Additional Details About Entity Data Model Metadata  831

Index  839