Book description
If you use Entity Framework in Visual Studio 2008 and .NET 3.5, this is the book you want. Programming Entity Framework, 1st Edition offers experienced developers a thorough introduction to Microsoft's core framework for modeling and interacting with data in .NET applications. This hands-on tour provides a deep understanding of Entity Framework's architecture and APIs, and explains how to use the framework in a variety of applications built with Visual Studio 2008 and .NET 3.5.
From the Entity Data Model (EDM) and Object Services to EntityClient and the Metadata Workspace, this highly acclaimed first edition covers it all.
- Understand the core concepts you need to make the best use of the Entity Framework (EF) in your applications
- Learn to query your data, using either LINQ to Entities or Entity SQL
- Create Windows Forms, WPF, and ASP.NET applications
- Build ASMX web services and WCF services
- Use Object Services to work directly with your entity objects
- Delve into model customization, relationship management, change tracking, data concurrency, and more
One important note: while many of the lessons from this book will continue to be valuable as you move to .NET 4, the thoroughly revised second edition of Programming Entity Framework (August 2010) specifically targets Visual Studio 2010 and .NET 4 -- where there have been many advancements and additions to the framework.
Publisher resources
Table of contents
- Programming Entity Framework
- A Note Regarding Supplemental Files
- Foreword
- Preface
-
1. Introducing the ADO.NET Entity Framework
- Programming Against a Model, Not Against the Database
- The Entity Data Model: A Client-Side Data Model
- The Entity in “Entity Framework”
- Choosing Your Backend
- Entity Framework Features
- The Entity Framework in Web Services
- What About ADO.NET DataSets and LINQ to SQL?
- Entity Framework Pain Points
- Programming the Entity Framework
-
2. Exploring the Entity Data Model
- Why Use an Entity Data Model?
- The EDM Within the Entity Framework
- Your First EDM
- The EDM in the Designer Window
- Entity Properties
- The Naked Model: Inspecting the Model’s XML
- A Less Daunting Model View
- The Three Parts of the Model
- CSDL: The Conceptual Schema
- SSDL: The Store Schema
- MSL: The Mappings
- Database Views in the EDM
- Code Generation from EDM to Classes
- Summary
-
3. Querying Entity Data Models
- Query the Model, Not the Database
- Your First EDM Query
- LINQ to Entities Queries
- Entity SQL Queries That Return Objects
- Method-Based Syntax Queries for LINQ and Entity SQL
- The Shortest Query
- EntityClient: The Lowest-Level Method for Returning Streamed Data Through EDM Queries
- Translation to Database Queries
- Avoid Inadvertent Query Execution
- Summary
-
4. Exploring EDM Queries in Greater Depth
- Same Model, Friendlier Name
- Projections in Queries
- Projections in Entity SQL
-
Querying Across Associations
- Navigation to an EntityReference
- Filtering and Sorting with an EntityReference
- Navigating to Entity Collections
- Projecting Properties from EntityCollection Entities
- Filtering and Sorting with EntityCollections
- Aggregates with EntityCollections
- Entity SQL SET Operators
- Aggregates in LINQ Methods and Query Builder Methods
- Joins and Nested Queries
- Grouping
- Shaped Data Returned by Queries
- Deferred Loading and Eager Loading Queries
- Retrieving a Single Entity
- Retrieving a Single Entity with GetObjectByKey
- Entity SQL’s Wrapped and Unwrapped Results
- Summary
- 5. Modifying Entities and Saving Changes
- 6. Using Stored Procedures with the EDM
- 7. Tuning Up a Model
-
8. Data Binding with Windows Forms and WPF Applications
-
Data Binding with Windows Forms Applications
- Creating a Windows Forms Application
- Using Windows Forms Data Sources to Help with Data Binding
- Creating an Object Data Source for a Customer Entity
- Getting the Entity’s Details onto the Form
- Adding Code to Perform the EDM Query
- Testing the Sample
- Entities, BindingSources, and a Very Important Rule
- Adding the Related EntityCollection to the Form
- Allowing the User to Edit the Data
- Editing the Navigation Properties (and Trimming Down the Query)
- Adding New Customers
-
Data Binding with WPF Applications
- Creating the WPF Form
- Creating the New Project
- Adding Code to Query the Entities That Drive the Form
- XAML’s Role in Data Binding
- Binding with the ListBox
- Testing the Example
- Selecting an Entity and Seeing Its Details
- Adding Another EntityCollection to the Mix: Activities
- Editing Trip Entities and Their Related Data
- Adding Items to the Child EntityCollection
- The Last Task: Adding New Trips to the Catalog
- Summary
-
Data Binding with Windows Forms Applications
-
9. Working with Object Services
- Where Does Object Services Fit into the Framework?
- Query Processing
- Object Materialization
- The ObjectContext
- State Management and ObjectStateEntry
- Relationship Management
- Sending Changes Back to the Database
- Additional Features
- Summary
- 10. Customizing Entities
-
11. Using the ASP.NET EntityDataSource Control
- Getting to First Base with the EntityDataSource Control and Flat Data
- Understanding How the EntityDataSource Is Able to Retrieve and Update Your Data
-
Working with Related EntityReference Data
- Using EntityDataSource.Include to Get Related Data
- Displaying Data That Comes from EntityReference Navigation Properties
- Using a New EntityDataSource Control to Enable Editing of EntityReference Navigation Properties
- Editing EntityReferences That Cannot Be Satisfied with a Drop-Down List
- Binding an EntityDataSource to Another Control with WhereParameters
- Editing Related Data Concurrently with Multiple EntityDataSource Controls
-
Working with Hierarchical Data in a Master/Detail Form
- Setting Up the Web Application
- Specifying Your Own Entity SQL Query Expression for an EntityDataSource
- Binding a DropDownList to an EntityDataSource Control
- Creating a Parent EntityDataSource That Is Controlled by the DropDownList and Provides Data to a DetailsView
- Using the EntityDataSource.Where Property to Filter Query Results
- Displaying Read-Only Child Data Through the Parent EntityDataSource
- Using a New EntityDataSource to Add a Third Level of Hierarchical Data to the Master/Detail Form
- Using the EntityDataSource.Inserting Event to Help with Newly Added Entities
- Testing the Application
- Browsing Through the EntityDataSource Events
- Summary
-
12. Customizing Entity Data Models
- Designer Support for Mappings
-
Mapping Table per Type Inheritance for Tables That Describe Derived Types
- Mapping TPT Inheritance
- Fixing the Impact of the New Inheritance on the Customer’s Associations with Other Entities
- Handling Properties with the Same Name
- Querying Inherited Types
- Creating a Project to Test the New Mappings
- Testing the TPT Inheritance
- SaveChanges and Newly Added Derived Types
- Specifying or Excluding Derived Types in Queries
- Creating New Derived Entities When the Base Entity Already Exists
- TPT with Abstract Types
- Using Entity Splitting to Map a Single Entity to More Than One Table
- Using Conditional Mapping to Filter Entity Mappings
- Implementing Table per Hierarchy Inheritance for Tables That Contain Multiple Types
- Implementing Customizations That Are Not Supported by the EDM Designer
- Mapping Table per Concrete (TPC) Type Inheritance for Tables with Overlapping Fields
-
Creating Complex Types to Encapsulate Sets of Properties
- Complex Types and the EDM Designer
- Defining a Complex Type
- Replacing Properties with a Complex Type
- Mapping Entities with Complex Types
- Complex Types Are Not EntityObjects
- Using Complex Types
- Complex Types in Data-Binding Scenarios
- Data Binding Complex Types in ASP.NET Without the EntityDataSource
- Windows Forms DataSource and Complex Types
- Removing the Complex Types from the Model
- Using QueryView to Create Read-Only Entities and Other Specialized Mappings
- Additional Customization Options
- Summary
-
13. Working with Stored Procedures When Function Mapping Won’t Do
- Does the Procedure Line Up with an Entity?
- Overview of Procedures, UDFs, and TVFs in the EDM
- Composing Queries Against Functions
- Mapping and Executing Query Stored Procedures
- Adding Native Queries to the Model
- Adding Native Views to the Model
- Using Commands That Affect the Persisted Database
- Defining Insert, Update, and Delete Stored Procedures Directly in the Model
- Mapping Insert/Update/Delete to Types Within an Inheritance Structure
- Implementing and Querying with User-Defined Functions (UDFs)
- Summary
-
14. Using Entities with Web and WCF Services
- Building a Client That Is Ignorant of the Entity Framework
- Using the Entity Framework with ASMX Web Services
-
Using the Entity Framework with WCF Services
-
Building the WCF Service
- Creating the service application
- Defining the operations the service will provide
- Defining the DataContract classes the service will use
- Enabling the model’s partial class properties for Trip and Reservation to participate in the service
- Implementing the service interface
- Adding graphs to ObjectContext
- Deleting objects
- Updating the ObjectGraph
- Client rules for identifying changes in an EntityCollection
- The UpdateCustomer method
- Why call ApplyPropertyChanges if there were no changes?
- Handling existing reservations
- Dealing with new reservations
- Deleting reservations
- Wrapping up the UpdateCustomer method with SaveChanges
- Building the Client to Consume the WCF Service
-
Building the WCF Service
- Summary
-
15. Working with Relationships and Associations
- Deconstructing Relationships in the Entity Data Model
-
Deconstructing Relationships Between Instantiated EntityObjects
- Relationships Are First-Class Citizens
- The “Platinum Rule” About Related Entities That Are Attached or Detached from the ObjectContext
- The Relationship Manager and the IRelatedEnd Interface
- Experimenting with Relationship Span
- Understanding Navigation Properties in Entity Objects
- Referential Integrity and Constraints
- Deletes and Cascading Deletes
- Defining Relationships Between Entities
- Learning a Few Last Tricks to Make You a Relationship Pro
- Summary
-
16. Making It Real: Connections, Transactions, Performance, and More
- EntityConnection and Database Connections in the Entity Framework
- The Entity Framework and Transactions
- The Entity Framework and Security
- The Entity Framework and Performance
- Entities in Multithreaded Applications
- Summary
-
17. Controlling Objects with ObjectStateManager and MetadataWorkspace
- Managing ObjectStateEntry Objects with ObjectStateManager
- Getting an ObjectStateManager and Its Entries
- CurrentValues and OriginalValues
-
Building the ObjectStateEntry Visualizer
- Setting Up the Project and Code File
- Retrieving an ObjectStateEntry Using an EntityKey
- Reading the OriginalValues and CurrentValues of an ObjectStateEntry
- Determining Whether a Property Has Been Modified
- Displaying the ObjectStateEntry’s State and Entity Type
- Getting ComplexType Properties Out of ObjectStateEntry
- Modifying Values with ObjectStateManager
- Working with Relationships in ObjectStateManager
- ObjectStateManager and SavingChanges
-
The MetadataWorkspace API
- Loading the MetadataWorkspace
- Clearing the MetadataWorkspace from Memory
- The MetadataWorkspace ItemCollections
- ItemCollections Are Loaded as Needed with EntityCollection
- Reading Metadata from the MetadataWorkspace
- Querying the Items
- Building Entity SQL Queries Dynamically Using Metadata
- Reading the Results of a Dynamically Created Query
- Dynamic Entity SQL and Generics for Reference Lists
- Creating EntityObjects Without Entity Classes
- Creating Entities and Graphs Dynamically
- Summary
-
18. Handling Entity Framework Exceptions
- Preparing for Exceptions in Entity Framework Code
- EntityConnectionString Exceptions
- Query Compilation Exceptions
- Creating a Common Wrapper to Handle Query Execution Exceptions
- SaveChanges Command Execution Exceptions
- ObjectStateEntries Returned by Object Services Exceptions
- InvalidOperationExceptions
- Exceptions When Multiple Parties Edit Data Concurrently
- Understanding Optimistic Concurrency Options in the Entity Framework
-
Implementing Optimistic Concurrency with the Entity Framework
- Flagging a Property for Concurrency Checking
- How the Entity Framework Uses the ConcurrencyMode Property
- Concurrency Checking Without a rowversion Field
- Concurrency Checking on a Checksum in the Data Store
- Concurrency Checks for EntityReference Navigation Properties
- Concurrency Checks and Inherited Types
- Concurrency Checks and Stored Procedures
- Handling OptimisticConcurrencyExceptions
- Handling Concurrency Exceptions at a Lower Level
- Handling Exceptions When Transactions Are Your Own
- Summary
-
19. Using Your Own Custom Classes
-
Mapping Classes to the Entity Data Model
- Mapping Rules for Custom Classes and Their Properties
- Inheriting from EntityObject
- Metadata Attributes
- Entity Classes
- Scalar Properties
- Navigation Properties
- Mapping the Remaining Entities in the Model
- Mapping the EntityContainer
- Resolving Conflicts Between Custom Classes and Designer-Generated Classes
- Querying Using the Custom Classes
- Implementing the IPOCO Interfaces
- Custom Class Assemblies and Entity Data Model Files
- Summary
-
Mapping Classes to the Entity Data Model
-
20. Using the Entity Framework in n-Tier Client-Side Applications
- Thinking in Layers
- Finding Your Motivation: A Master/Detail Data Entry Form That Will Use the DataBridge Class
- Preventing Non-UI Logic from Leaking into the UI
- Implementing Logic That Fits Best in the Entity Partial Classes
- Building the CommandExecutor Class
-
Building the DataBridge Class
- Using a Long-Running ObjectContext
- Implementing the Primary Elements of the DataBridge Class
- Creating a Class for Lightweight Objects to Be Used in UI Pick Lists
- Creating the Main Entity Pick List: For Customer Names
- Using MergeOptions to Cache or Refresh a Pick List
- Building a Frequently Used Entity Graph for the UI
- Supplying Additional Lists for UI Drop-Downs
- Saving Changes
- Rolling Back User Changes
- Using the DataBridge Class for Data Binding in a Master/Detail Form
- Allowing Users to Roll Back Their Edits
- Helping the User Who Forgets to Save Changes
- Summary
-
21. Using the Entity Framework in n-Tier ASP.NET Applications
- Understanding How an ObjectContext Fits into the Web Page Life Cycle
- Introducing ASP.NET’s ObjectDataSource Control
- Designing Object Provider Classes to Be Used with an ObjectDataSource
- Wiring Up the Provider Classes to ObjectDataSource Controls
- Understanding Why We Didn’t Use Object Graphs in This Business Layer
- Summary
-
22. Implementing a Smarter WCF Service for Working with Entities
- Will Your Client Agree to Your Data Contract?
- Shipping DTOs, Not EntityObjects
- Creating EntityState Properties That Do Not Rely on ObjectContext
- Designing the Service Interface
-
Implementing the Service Operations
- Returning CustomerList as ShortCustomers with GetCustomerList
- Returning Additional Reference Lists
- Returning a Single Entity Graph for Editing with GetCustomer
- Building Methods to Create DTOs from Entity Objects
- Initializing the DTO Children
- Saving Edits Sent Back from the Client with SaveCustomer
- Building the Main Method for Updating the Graph: SaveCustomer
- UpdateChildren
- Implementing the Client That Will Use the WCF Service
- Testing It All with a Simple Console Application
- Summary
- 23. The Entity Framework, Today and Tomorrow
- A. Entity Framework Assemblies and Namespaces
- Index
- About the Author
- Colophon
- Copyright
Product information
- Title: Programming Entity Framework
- Author(s):
- Release date: January 2009
- Publisher(s): O'Reilly Media, Inc.
- ISBN: 9780596555412
You might also like
book
Programming Entity Framework: Code First
Take advantage of the Code First data modeling approach in ADO.NET Entity Framework, and learn how …
book
Programming Entity Framework, 2nd Edition
Get a thorough introduction to ADO.NET Entity Framework 4 -- Microsoft's core framework for modeling and …
book
Programming Entity Framework: DbContext
The DbContext API captures Entity Framework’s (EF) most commonly used features and tasks, simplifying development with …
book
Entity Framework 6 Recipes, Second Edition
Entity Framework 6 Recipes provides an exhaustive collection of ready-to-use code solutions for Entity Framework, Microsoft's …