Table of Contents

Copyright

Brief Table of Contents

Table of Contents

Foreword

Preface

Acknowledgments

About this Book

About the Cover Illustration

1. Redefining your data-access strategy

Chapter 1. Data access reloaded: Entity Framework

1.1. Getting started with data access

1.2. Developing applications using database-like structures

1.2.1. Using datasets and data readers as data containers

1.2.2. The strong coupling problem

1.2.3. The loose typing problem

1.2.4. The performance problem

1.3. Using classes to organize data

1.3.1. Using classes to represent data

1.3.2. From a single class to the object model

1.4. Delving deep into object/relational differences

1.4.1. The datatype mismatch

1.4.2. The association mismatch

1.4.3. The granularity mismatch

1.4.4. The inheritance mismatch

1.4.5. The identity mismatch

1.4.6. Handling the mismatches

1.5. Letting Entity Framework ease your life

1.5.1. What is O/RM?

1.5.2. The benefits of using Entity Framework

1.5.3. When isn’t O/RM needed?

1.6. How Entity Framework performs data access

1.6.1. The Entity Data Model

1.6.2. Object Services

1.6.3. Entity Client data provider

1.6.4. LINQ to Entities

1.6.5. Entity SQL

1.7. Summary

Chapter 2. Getting started with Entity Framework

2.1. Introducing the OrderIT example

2.2. Designing the OrderIT model and database

2.2.1. Bottom-up vs. top-down design

2.2.2. Customers and suppliers

2.2.3. Products

2.2.4. Orders

2.3. Structuring the application

2.3.1. Creating the assemblies

2.3.2. Designing entities using the database-first approach

2.3.3. Designing relationships

2.3.4. Organizing the generated code

2.3.5. The model-first approach in the designer

2.4. A sneak peek at the code

2.4.1. Querying the database

2.4.2. Updating objects and reflecting changes into storage

2.5. Summary

2. Getting started

Chapter 3. Querying the object model: the basics

3.1. One engine, many querying methods

3.2. The query engine entry point: Object Services

3.2.1. Setting up the connection string

3.2.2. Writing queries against classes

3.2.3. LINQ to Entities queries vs. standard LINQ queries

3.2.4. Retrieving data from the database

3.2.5. Understanding Identity Map in the context

3.2.6. Understanding interaction between Object Services and Entity Client

3.2.7. Capturing the generated SQL

3.2.8. Understanding which entities are returned by a query

3.2.9. When is a query executed?

3.2.10. Managing the database from the context

3.3. Summary

Chapter 4. Querying with LINQ to Entities

4.1. Filtering data

4.1.1. Filtering data based on associations

4.1.2. Paging results

4.1.3. Retrieving one entity

4.1.4. Creating queries dynamically

4.2. Projecting results

4.2.1. Projecting with associations

4.2.2. Projections and object tracking

4.3. Grouping data

4.3.1. Filtering aggregated data

4.4. Sorting

4.4.1. Sorting with associations

4.5. Joining data

4.6. Querying with inheritance

4.7. Using functions

4.7.1. Canonical functions

4.7.2. Database functions

4.8. Executing handmade queries

4.8.1. Working with parameters

4.9. Fetching

4.9.1. Eager loading

4.9.2. Lazy loading

4.9.3. Manual deferred loading

4.9.4. Choosing a loading approach

4.10. Summary

Chapter 5. Domain model mapping

5.1. The Entity Data Model

5.1.1. The Entity Data Model and Visual Studio designer

5.2. Creating consumable entities

5.2.1. Writing the entities

5.2.2. Describing entities in the conceptual schema

5.2.3. Describing the database in the storage schema

5.2.4. Creating the mapping file

5.3. Defining relationships in the model

5.3.1. One-to-one relationships

5.3.2. One-to-many relationships

5.3.3. Many-to-many relationships

5.3.4. Some tips about relationships

5.4. Mapping inheritance

5.4.1. Table per hierarchy inheritance

5.4.2. Table per type inheritance

5.5. Extending the EDM with custom annotations

5.5.1. Customizing the EDM

5.6. Summary

Chapter 6. Understanding the entity lifecycle

6.1. The entity lifecycle

6.1.1. Understanding entity state

6.1.2. How entity state affects the database

6.1.3. State changes in the entity lifecycle

6.2. Managing entity state

6.2.1. The AddObject method

6.2.2. The Attach method

6.2.3. The ApplyCurrentValues and ApplyOriginalValues methods

6.2.4. The DeleteObject method

6.2.5. The AcceptAllChanges method

6.2.6. The ChangeState and ChangeObjectState methods

6.2.7. The Detach method

6.3. Managing change tracking with ObjectStateManager

6.3.1. The ObjectStateEntry class

6.3.2. Retrieving entries

6.3.3. Modifying entity state from the entry

6.3.4. Understanding object tracking

6.3.5. Understanding relationship tracking

6.3.6. Change tracking and MergeOption

6.4. Summary

Chapter 7. Persisting objects into the database

7.1. Persisting entities with SaveChanges

7.1.1. Detecting dirty entities

7.1.2. Starting database transactions

7.1.3. SQL code generation and execution

7.1.4. Database transaction commit or rollback

7.1.5. Committing entities

7.1.6. Overriding SaveChanges

7.2. Persisting changed entities into the database

7.2.1. Persisting an entity as a new row

7.2.2. Persisting modifications made to an existing entity

7.2.3. Persisting entity deletion

7.3. Persisting entities graphs

7.3.1. Persisting a graph of added entities

7.3.2. Persisting modifications made to a graph

7.3.3. Persisting deletions made to a graph

7.3.4. Persisting many-to-many relationships

7.4. A few tricks about persistence

7.4.1. Handling persistence exceptions

7.4.2. Executing custom SQL commands

7.5. Summary

Chapter 8. Handling concurrency and transactions

8.1. Understanding the concurrency problem

8.1.1. The concurrent updates scenario

8.1.2. A first solution: pessimistic concurrency control

8.1.3. A better solution: optimistic concurrency control

8.1.4. The halfway solution: pessimistic/optimistic concurrency control

8.2. Handling concurrency in Entity Framework

8.2.1. Enabling optimistic concurrency checking

8.2.2. Optimistic concurrency in action

8.2.3. Catching concurrency exceptions

8.2.4. Managing concurrency exceptions

8.3. Managing transactions

8.3.1. The transactional ObjectContext

8.3.2. Transactions and queries

8.4. Summary

3. Mastering Entity Framework

Chapter 9. An alternative way of querying: Entity SQL

9.1. Query basics

9.2. Filtering data

9.2.1. Working with associations

9.2.2. Paging results

9.3. Projecting results

9.3.1. Handling projection results

9.3.2. Projecting with associations

9.4. Grouping data

9.5. Sorting data

9.5.1. Sorting data based on associations

9.6. Joining data

9.7. Querying for inheritance

9.8. Using query-builder methods

9.8.1. Chaining methods

9.8.2. Query-builder methods vs. LINQ to Entities methods

9.8.3. Using parameters to prevent injection

9.9. Working with the Entity Client data provider

9.9.1. Connecting with EntityConnection

9.9.2. Executing queries with EntityCommand

9.9.3. Processing query results with EntityDataReader

9.9.4. Going beyond querying with Entity Client

9.10. Summary

Chapter 10. Working with stored procedures

10.1. Mapping stored procedures

10.1.1. Importing a stored procedure using the designer

10.1.2. Importing stored procedures manually

10.2. Returning data with stored procedures

10.2.1. Stored procedures whose results match an entity

10.2.2. Stored procedures whose results don’t match an entity

10.2.3. Stored procedures that return scalar values

10.2.4. Stored procedures that return an inheritance hierarchy

10.2.5. Stored procedures with output parameters

10.3. Embedding functions in the storage model

10.4. Updating data with stored procedures

10.4.1. Using stored procedures to persist an entity

10.4.2. Using stored procedures to update an entity with concurrency

10.4.3. Persisting an entity that’s in an inheritance hierarchy

10.4.4. Upgrading and downgrading an entity that’s in an inheritance hierarchy

10.4.5. Executing stored procedures not connected to an entity

10.5. Summary

Chapter 11. Working with functions and views

11.1. Views in the storage model: defining queries

11.1.1. Creating a defining query

11.1.2. Mapping stored procedures to classes with complex properties

11.2. User-defined functions and scalar-valued functions

11.2.1. Scalar-valued functions

11.2.2. User-defined functions

11.2.3. User-defined functions and collection results

11.3. Summary

Chapter 12. Exploring EDM metadata

12.1. Metadata basics

12.1.1. Accessing metadata

12.1.2. How metadata is internally organized

12.1.3. Understanding when metadata becomes available

12.2. Retrieving metadata

12.2.1. Understanding the metadata object model

12.2.2. Extracting metadata from the EDM

12.3. Building a metadata explorer

12.3.1. Populating entities and complex types

12.3.2. Populating functions

12.3.3. Populating containers

12.3.4. Populating storage nodes

12.4. Writing generic code with metadata

12.4.1. Adding or attaching an object based on custom annotations

12.4.2. Building a generic GetById method

12.5. Summary

Chapter 13. Customizing code and the designer

13.1. How Visual Studio generates classes

13.1.1. Understanding template tags

13.1.2. Understanding directives

13.1.3. Writing code

13.2. Customizing class generation

13.2.1. Understanding the available POCO template

13.2.2. Generating user-defined and scalar-valued functions

13.2.3. Generating data-annotation attributes

13.2.4. Extending classes through partial classes

13.3. How Visual Studio generates database DDL

13.3.1. Choosing the workflow

13.3.2. Generating SSDL, MSL, and DDL

13.4. Customizing DDL generation

13.4.1. Understanding the conceptual-to-storage template

13.4.2. Understanding the conceptual-to-mapping template

13.4.3. Understanding the storage-to-database script template

13.5. Creating designer extensions

13.5.1. How the property-extension mechanism works

13.5.2. Setting up the project containing the extension

13.5.3. Creating the property class

13.5.4. Creating the factory class

13.5.5. Creating the manifest extension file

13.5.6. Installing, debugging, and uninstalling the extension

13.6. Summary

4. Applied Entity Framework

Chapter 14. Designing the application around Entity Framework

14.1. The application design process

14.2. A typical three-layer architecture

14.2.1. Filling the product list

14.2.2. Calculating order totals and saving them to the database

14.2.3. Dealing with higher levels of complexity

14.3. Principles of domain-driven design

14.3.1. Entities

14.3.2. Value objects

14.3.3. Handling associations correctly: domain roots and aggregates

14.3.4. Refining the model

14.4. Retrieving references to a domain’s entities

14.4.1. Repositories at a glance

14.4.2. Implementing a repository

14.4.3. Getting a reference to a brand new entity

14.5. Summary

Chapter 15. Entity Framework and ASP.NET

15.1. EntityDataSource, a new approach to data binding

15.1.1. A practical guide to data source controls

15.1.2. The EntityDataSource control in depth

15.2. Using Dynamic Data controls with Entity Framework

15.2.1. Registering the model

15.2.2. Working with data annotations

15.3. The ObjectContext lifecycle in ASP.NET

15.3.1. The Context-per-Request pattern

15.3.2. Wrapping the context

15.3.3. A module to handle the lifecycle

15.3.4. Using the repository in a page

15.4. Common scenarios involving ASP.NET and Entity Framework

15.5. Summary

Chapter 16. Entity Framework and n-tier development

16.1. n-Tier problems and solutions

16.1.1. Tracking changes made on the client

16.1.2. Choosing data to be exchanged between server and client

16.1.3. The serialization problem

16.2. Developing a service using entities as contracts

16.2.1. Persisting a complex graph

16.2.2. Optimizing data exchanges between client and server

16.2.3. Dealing with serialization in WCF

16.3. Developing a service using DTOs

16.3.1. Persisting a complex graph

16.4. Developing a service using STEs

16.4.1. Enabling STEs

16.4.2. Inside an STE

16.4.3. Inside the context

16.4.4. Using STEs

16.4.5. STE pros and cons

16.5. Summary

Chapter 17. Entity Framework and Windows applications

17.1. An example application

17.2. Designing model classes for binding

17.2.1. Implementing INotifyPropertyChanged

17.2.2. Implementing IEditableObject

17.2.3. Implementing IDataErrorInfo

17.2.4. Using a template to generate the binding code

17.3. Binding in Windows Forms applications

17.3.1. Showing orders

17.3.2. Showing data for the selected order

17.3.3. Showing details of the selected order

17.3.4. Showing selected detail information

17.3.5. Adding code to persist modifications

17.3.6. Taking advantage of binding interfaces

17.4. Binding in WPF applications

17.4.1. Showing orders

17.4.2. Showing data for the selected order

17.4.3. Showing selected order details

17.4.4. Showing selected detail information

17.4.5. Adding code to persist modifications

17.5. Summary

Chapter 18. Testing Entity Framework

18.1. Unit tests at a glance

18.2. Writing a test suite in Visual Studio 2010

18.2.1. Testing a simple method

18.2.2. Advanced features of Microsoft’s Unit Testing Framework

18.3. Isolating dependencies

18.3.1. Refactoring for testability

18.3.2. Using a mocking framework to fake dependencies

18.4. Unit-testing the data access layer

18.4.1. A test infrastructure for a repository

18.4.2. Testing LINQ to Entities queries

18.5. Testing the persistence and retrieval of an entity

18.6. Summary

Chapter 19. Keeping an eye on performance

19.1. Testing configuration and environment

19.1.1. The performance test visualizer

19.1.2. Building the timer

19.2. Database-writing comparison

19.3. Query comparisons in the default environment

19.4. Optimizing performance

19.4.1. Pregenerating views

19.4.2. Compiling LINQ to Entities queries

19.4.3. Enabling plan caching for Entity SQL

19.4.4. Disabling tracking when it’s not needed

19.4.5. Optimizing stored procedures

19.5. Summary

Appendix A. Understanding LINQ

A.1. Why was LINQ created?

A.2. Type inference

A.3. Extension methods

A.3.1. Method chaining

A.3.2. Method evaluation

A.4. Lambda expressions

A.4.1. Anonymous methods

A.4.2. From anonymous methods to lambda expressions

A.5. Object initializers

A.6. Anonymous types

A.7. Query syntax

A.8. Deferred execution

A.8.1. Runtime query composition

Appendix B. Entity Framework tips and tricks

B.1. A smart way of attaching entities

B.1.1. Attaching an entity as Modified or Deleted

B.1.2. Modifying only selected properties after attaching

B.2. Building an auditing system

B.2.1. Creating an attribute to mark auditable entities

B.2.2. Customizing the designer

B.2.3. Customizing the template that generates entities

B.2.4. Overriding the persistence process with a custom context

B.2.5. Customizing the context template

B.2.6. Using the code

B.3. Two tips for querying data

B.3.1. Improving the Include method

B.3.2. Enabling full text search in Entity Framework

B.4. Working with special database types

Index

List of Figures

List of Tables

List of Listings

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.147.77.208