Home Page Icon
Home Page
Table of Contents for
Index
Close
Index
by Julia Lerman
Programming Entity Framework
Programming Entity Framework
A Note Regarding Supplemental Files
Foreword
Preface
Who This Book Is For
How This Book Is Organized
What You Need to Use This Book
This Book’s Website
Conventions Used in This Book
Using Code Examples
Safari® Books Online
Comments and Questions
Acknowledgments
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
Available Providers
Access and ODBC
Entity Framework Features
The Entity Data Model
Entity Data Model Design Tools
The Entity Data Model Wizard
Managing Objects with Object Services
Change Tracking
Relationship Management
Data Binding
EntityClient
The Entity Framework in Web Services
What About ADO.NET DataSets and LINQ to SQL?
DataSets
LINQ to SQL
Entity Framework Pain Points
The Entity Framework Designer
Stored procedures
Unsupported EDM types
Generating a database from the model
A host of little things
Challenges with Change Tracking Distributed Applications
Domain-Driven Development
Unit Testing
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
Editing the Entity Set and Navigation Property Names
The Naked Model: Inspecting the Model’s XML
A Less Daunting Model View
The Three Parts of the Model
CSDL: The Conceptual Schema
Schema
EntityContainer
EntitySet
EntityType
The Key element
The Property elements
The navigation properties
Associations
AssociationSet
NavigationProperty
Navigation Properties That Return Collections
Where Are the Foreign Keys?
SSDL: The Store Schema
Association and AssociationSet
ReferentialConstraint
MSL: The Mappings
The MSL Elements
Mapping
EntityContainerMapping
EntitySetMapping
EntityTypeMapping
MappingFragment
ScalarProperty
AssociationSetMapping
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
A More Query-Like Query
Where Did the Context and Classes Come from?
The ObjectContext class, ProgrammingEFDB1Entities
The entity classes
LINQ to Entities Queries
ObjectQuery and LINQ to Entities
Entity SQL Queries That Return Objects
Why Another Way to Query?
Entity SQL
Entity SQL canonical functions
The Parameterized ObjectQuery
Method-Based Syntax Queries for LINQ and Entity SQL
LINQ Method-Based Queries
Chaining methods
ObjectQuery’s Query Builder Methods
Specifying the control variable
The Shortest Query
EntityClient: The Lowest-Level Method for Returning Streamed Data Through EDM Queries
EntityConnection and the Connection String
EntityCommand
ExecuteReader
Forward-Only Access to the Fields
Translation to Database Queries
Pay Attention to the .NET Method’s Impact on Generated SQL
Avoid Inadvertent Query Execution
Summary
4. Exploring EDM Queries in Greater Depth
Same Model, Friendlier Name
Projections in Queries
Projections in LINQ to Entities
VB and C# syntax differences
LINQ Projections and New Language Features
Anonymous types
Implicitly typed local variables
Implicit and explicit anonymous type creation
Projections with LINQ Query Methods
Projections in Entity SQL
DbDataRecords and Nonscalar Properties
Projecting with Query Builder Methods
Querying Across Associations
Navigation to an EntityReference
Filtering and Sorting with an EntityReference
Navigating to Entity Collections
Projecting Properties from EntityCollection Entities
Shaped results
Flattened results
Filtering and Sorting with EntityCollections
Aggregates with EntityCollections
Aggregates in LINQ to Entities
Aggregates in Entity SQL
Entity SQL SET Operators
Aggregates in LINQ Methods and Query Builder Methods
Joins and Nested Queries
Joins
Nested Queries
Using a nested LINQ query as a projection
Using a nested LINQ query as the collection to be queried
Nested queries in Entity SQL
Grouping
Naming Properties When Grouping
Chaining Aggregates
Filtering on Group Conditions
Grouping in Entity SQL
Returning entities from an Entity SQL GROUP BY query
Filtering based on group properties
Shaped Data Returned by Queries
Shaped Data from Entity SQL
Deferred Loading and Eager Loading Queries
Deferred Loading Entity Collections with Load
Performance considerations with deferred loading
Loading the EntityReference
Using the Include Method to Eager-Load
How is the data shaped with Include?
Accessing properties from an Include in the query
Using Include with an ObjectQuery
Pros and Cons of Load and Include
Retrieving a Single Entity
Retrieving a Single Entity with GetObjectByKey
Entity SQL’s Wrapped and Unwrapped Results
Entity SQL Rules for Wrapped and Unwrapped Results
Digging a Little Deeper into EntityClient’s Results
Summary
5. Modifying Entities and Saving Changes
How ObjectContext Manages Entities
Remembering Original Values and Keeping Track of Changes
The SaveChanges Method
From Entity Framework Command to Native Command
Adding New Entities
Breaking Down the Native Insert Command
Inserting New Parents and Children
Deleting Entities
Summary
6. Using Stored Procedures with the EDM
Adding the Stored Procedures into the Model
Working with Functions
Function Attributes
Implementing Functions
Rules for Mapping Functions to Entities
Wiring Up Insert, Update, and Delete Functions to an Entity
The Use Original Value option
Inspecting the Mappings in the XML
Using These Mapped Functions
What about the read stored procedure?
The EDM Designer’s Model Browser
Mapping the Last of the Four Functions: CustomersbyState
Using the CustomersbyState Function
Using Functions in a Query
More About the Update Model Wizard
A Frequently Asked Question About Deleting Entities from the Model
Summary
7. Tuning Up a Model
The BreakAway Geek Adventures Business Model
Creating a Class Library Project to Host an EDM
Inspecting and Cleaning Up a New Model
Modifying the Names of Entities
Collisions Between Property Names and Entity Names
Cleaning Up Navigation Property Names
Entities with Multiple Relationships to a Single Entity
Determining Which Navigation Property Is Mapped to Which Foreign Key Field
Mapping a Few Stored Procedures
Mapping the Insert Function
Mapping the Update Function
Using the Use Original Value checkbox
The DeleteFunction mapping and an awkward stored procedure parameter
Working with Many-to-Many Relationships
Building the BreakAwayModel Project
Don’t Overlook the Assembly and Model Names
BAGA assembly namespace
Entity container name
Model namespace
The Impact of Compiling a Project on an EDMX File
Splitting out the schema files
Moving the schema files
Summary
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
Displaying the properties of reference properties in the grid
Testing the new version of the sample
Allowing the User to Edit the Data
Enabling the Save button
Changing the scope of the ObjectContext
Adding the save logic to the Save button
Test editing a customer
Editing the Navigation Properties (and Trimming Down the Query)
Reorganizing data retrieval
Replacing the navigation property TextBoxes with ComboBoxes
Testing the sample again
Adding New Customers
From toolbar to BindingSource to context
Adding the code to ensure that new customers are created properly
Testing the form’s add functionality
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
Binding the TextBox controls to the ListBox
Binding the ComboBox controls to the ListBox and to the data
Testing the sample
Adding Another EntityCollection to the Mix: Activities
The *:* relationship between trips and activities
Modifying the code to eager-load the related activities
Adding the Activities ListBox and binding it to the Trips ListBox
Testing the application again
Editing Trip Entities and Their Related Data
What if the user changes the destination?
Adding Items to the Child EntityCollection
Testing the new feature for adding activities
The Last Task: Adding New Trips to the Catalog
A few WPF tricks for a more interactive ListBox
Coding the Add New Trip feature
Validating the new trip before saving
Testing the final version of the WPF demo
Summary
9. Working with Object Services
Where Does Object Services Fit into the Framework?
Query Processing
From Query to Command Tree to SQL
From a LINQ to Entities query to a command tree
From Entity SQL and query builder methods to a command tree
How EntityClient turns command trees into store commands
A Better Understanding of Query Builder Methods
Query builder methods and EntitySets
From query builder methods to Entity SQL expressions
Combining LINQ methods and query builder methods
Breaking Apart the ObjectQuery
ToTraceString
ObjectQuery.CommandText
ObjectQuery.Parameters
ObjectQuery.Context
Query Execution with the ToList or ToArray Method
Query Execution with the Execute Method
ObjectContext.Connection
Why does the context need the EntityConnection?
Handling Command Execution with EntityClient
Object Materialization
The ObjectContext
ObjectContext Is a Cache for In-Memory Objects
Objects are not required to be in the ObjectContext cache
Entity Objects
EntityKey and EntityState
The EntityState enums
Merging Results into the Cache
State Management and ObjectStateEntry
Change Tracking
Relationship Management
Attaching and Detaching Objects from the ObjectContext
ObjectContext.Add
ObjectContext.Attach
ObjectContext.AttachTo
Creating an EntityKey on the fly
ObjectContext.ApplyPropertyChanges: A Handy Method for Updating Entities
Sending Changes Back to the Database
ObjectContext.SaveChanges
SaveChanges Returns an Integer
Data Validation with the SavingChanges Event
Concurrency Management
Optimistic concurrency
ConcurrencyMode
OptimisticConcurrencyException
Transaction Support
Additional Features
Object Services Supports XML and Binary Serialization
ObjectContext, ObjectStateManager, and ObjectStateEntry are not serializable
Automatic serialization
XML and DataContract serialization
Binary serialization
Serialization and object state
Explicit serialization
Object Services Supports Data Binding
Object Services Supports Custom Classes
IEntityWithChangeTracker
IEntityWithKey
IEntityWithRelationships
Summary
10. Customizing Entities
Partial Classes
Customizable Methods
The OnContextCreated Method
Implementing OnContextCreated
The On[Property]Changed and On[Property]Changing Methods
Implementing the property-level PropertyChanged and PropertyChanging methods
Using PropertyChanged to Calculate Database-Computed Columns Locally
Customizable Event Handlers
The ObjectContext.SavingChanges Event
Implementing SavingChanges
The EntityObject.PropertyChanging and EntityObject.PropertyChanged Events
The order of the Changing/Changed events
Event parameters
Implementing the class-level PropertyChanging and PropertyChanged events
The AssociationChanged Event
Event arguments
Other Opportunities for Customization
Custom Properties
Custom Properties That Perform Calculations on Child Collections
Overloading Context and Entity Methods
Partial Classes Are for More Than Just Overriding Existing Methods and Events
Custom Code Generation
Creating Common Methods or Properties for All Entities
Summary
11. Using the ASP.NET EntityDataSource Control
Getting to First Base with the EntityDataSource Control and Flat Data
Creating the Hello Entities Project
Creating a GridView and an EntityDataSource Concurrently
Configuring an EntityDataSource Through Its Wizard
Formatting the GridView
Testing the Web Application
Understanding How the EntityDataSource Is Able to Retrieve and Update Your Data
EntityDataSource and Its Query
Other EntityDataSource properties that impact the query
EntityDataSource and Its ObjectContext
Using your own context
EntityDataSource Context Events
EntityDataSource and ViewState
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
Coding the EntityDataSource’s Selected event to populate a control with navigation property details
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
EntityDataSource Events and Page 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
Merging Multiple Entities into One
Testing Entity Splitting
Using Conditional Mapping to Filter Entity Mappings
Creating a Conditional Mapping for the Activity Entity
The Is Null/Not Null conditions
Testing the Conditional Mapping
Filtering on other types of conditions
Removing the conditional mapping from Activity and re-creating the Category property
Implementing Table per Hierarchy Inheritance for Tables That Contain Multiple Types
Creating the Resort Derived Type
Setting a Default Value on the Table Schema
Testing the TPH Mapping
Abstract Entity Types
Which of These Mappings Is Better?
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
ASP.NET EntityDataSource
Data Binding Complex Types in ASP.NET Without the EntityDataSource
Complex types with ASP.NET binding controls
List controls
Data-bound controls
Templated controls
Windows Forms DataSource and Complex Types
Removing the Complex Types from the Model
Using QueryView to Create Read-Only Entities and Other Specialized Mappings
Creating a Simple QueryView
Testing the QueryView
Deconstructing the QueryView
QueryView with Inherited Types
When will the Entity Framework use the QueryView for the derived type?
The default QueryView needs to account for derived types
Testing the New QueryView
Additional Customization Options
Mapping Stored Procedures
Multiple Entity Sets per Type
Self-Referencing Associations
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
Using Functions That Match an Entity Whose Property Names Have Been Changed
How can you get around this problem?
Query Stored Procedures and Inherited Types
Queries That Return Randomly Shaped Results
Replacing Stored Procedures with Views
Queries That Return Multiple Resultsets
Queries That Return Primitive Types
Adding Native Queries to the Model
Adding Native Views to the Model
DefiningQuery Is Already in Your Model
Using DefiningQuery to Create Your Own Views
Implementing a DefiningQuery
Creating an association from the new entity
Testing the DefiningQuery
Using DefiningQuery to Solve More Complex Problems
Using Commands That Affect the Persisted Database
DML Functions That Return Entities
Insert, Update, and Delete Functions That Don’t Return an Entity
Returning a scalar value
Returning nothing
Defining Insert, Update, and Delete Stored Procedures Directly in the Model
What Do the Functions Look Like?
Mapping Insert/Update/Delete to Types Within an Inheritance Structure
What If Stored Procedures Affect Multiple Entities in 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
Pros and Cons of an Entity Framework-Agnostic Consumer
Using the Entity Framework with ASMX Web Services
Building the ASMX Service
Creating the web service
The GetCustomers method
Testing the GetCustomers service operation
Adding a method to return a single customer
Testing the new method
What about interoperability?
The insert and update web methods
The path of least resistance
Building the Client Application
Setting up the client project and the proxy to the service
Adding methods to interact with the web service
Designing the form
Adding the New and Save buttons
Testing your application
The client-side Customer versus the server-side Customer
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
Editing the configuration for the web service client
Testing the form again
Adding functionality to view the reservations
Testing the form so far
Finishing the form
Adding and deleting the reservations
Running the application and saving your changes
Peeking under the covers
Summary
15. Working with Relationships and Associations
Deconstructing Relationships in the Entity Data Model
How Did the Entity Data Model Wizard Create the Association?
Additional Items Created in the Model
Navigation Properties Are Not Required
Understanding How Associations Impact the Native Query
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
The Relationship Manager provides related objects through late binding
Experimenting with Relationship Span
Understanding Navigation Properties in Entity Objects
EntityReference properties
EntityReference.Value
What if there is no EntityReference
EntityCollection properties
Referential Integrity and Constraints
Constraints that are not checked until they hit the database
Constraints that the Entity Framework checks when SaveChanges is called
Deletes and Cascading Deletes
Cascading deletes in the database
Cascading deletes in the EDM
Recommendation: Cascade in both the model and the database, or in neither
Defining Relationships Between Entities
The CLR Way: Setting a Navigation Property
Setting an EntityReference Using an EntityKey
Loading, Adding, and Attaching Navigation Properties
Rules, rules, rules
EntityReference.Load and EntityCollection.Load
Load provides behind-the-scenes query creation and execution
Understanding why Load cannot be called on Added entities
EntityCollection.Add
Adding new entities that are detached
Adding new or existing entities that are attached
Adding entities to the EntityCollection of a detached object
Attach and Remove
Use Attach only when a relationship exists in the data store
Attach Versus Add
Moving an Entity to a New Graph
Learning a Few Last Tricks to Make You a Relationship Pro
Using CreateSourceQuery to Enhance Deferred Loading
Getting a Foreign Key Value
Summary
16. Making It Real: Connections, Transactions, Performance, and More
EntityConnection and Database Connections in the Entity Framework
EntityConnection Versus Database Connection
Programming EntityConnection Strings
Using the EntityConnectionStringBuilder Class
Dynamic EntityConnections
Opening and Closing Entity and Database Connections
Manually opening and closing connections
Default behavior 1: Many calls on a single connection
Default behavior 2: Multiple connections
Forcing an explicit connection
Connection versus Connection.StoreConnection
Taking Control of How Store Connections Are Disposed
What About Connection Pooling?
The Entity Framework and Transactions
Why Use Your Own Transaction?
Understanding the Entity Framework’s Default: Implicit Transactions
Where did the transaction come from?
Controlling AcceptAllChanges in a transaction
Specifying Your Own Transaction
Reading Queries Using System.Transaction or EntityTransaction
Can You Use Transactions Within ObjectContext?
The Entity Framework and Security
SQL Injection
You’re safe with LINQ, but be careful with Entity SQL
Entity SQL injection
Protecting Data from Connection Piggybacks
The Entity Framework and Performance
A Few “Backyard Benchmarks”
Interpreting the tests
Reducing the Cost of Query Compilation
The EDM Generator for Precompiled Views (and More)
What’s in a precompiled view code file?
Precompiling views against an existing project
Precompiled LINQ to Entities Queries
LINQ to Entities compiled queries
Query Plan Caching for Entity SQL
Entity SQL querying with EntityClient versus Object Services
What About Database Updates and Performance?
Entities in Multithreaded Applications
Forcing an ObjectContext to Use Its Own Thread
Another Spin on Threading: Concurrent Processing
Summary
17. Controlling Objects with ObjectStateManager and MetadataWorkspace
Managing ObjectStateEntry Objects with ObjectStateManager
An ObjectStateEntry Refresher
Getting an ObjectStateManager and Its Entries
Getting Groups of Entries with GetObjectStateEntries
Overloading GetObjectStateEntries using extension methods
Getting a Single Entry with GetObjectStateEntry and TryGetObjectStateEntry
Digging Through ObjectStateEntry
CurrentValues and OriginalValues
CurrentValueRecord.DataRecordInfo
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
RelationshipEntry EntityState
Inspecting the RelationshipEntries
Locating relationships for an entity
Building graphs directly with the RelationshipManager
ObjectStateManager and SavingChanges
The FieldMetadata Hierarchy
The MetadataWorkspace API
Loading the MetadataWorkspace
Creating a MetadataWorkspace without an EntityConnection
Clearing the MetadataWorkspace from Memory
The MetadataWorkspace ItemCollections
ItemCollections Are Loaded as Needed with EntityCollection
GetItemCollection/TryGetItemCollection
Reading Metadata from the MetadataWorkspace
GetItems/TryGetItems
GetItem/TryGetItem
GetFunctions/TryGetFunctions
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 a New Entity with CreateInstance
Getting a reference to an assembly
Creating an entity from the assembly
Using System.Type to Inspect the EntityType
Creating Entities and Graphs Dynamically
Calling the AddChildtoParentObject Method
Summary
18. Handling Entity Framework Exceptions
Preparing for Exceptions in Entity Framework Code
EntityConnectionString Exceptions
Connection String Can’t Be Found or Is Improperly Configured: System.ArgumentException
Metadata Files Cannot Be Found: System.Data.MetadataException
Handling Connection String Exceptions
Query Compilation Exceptions
Invalid LINQ to Entities Query Expressions: System.NotSupportedException
Invalid Entity SQL Query Expressions: EntitySQLException
Store Provider Issues: EntityCommandCompilationException
Creating a Common Wrapper to Handle Query Execution Exceptions
SaveChanges Command Execution Exceptions
Model and Mapping Constraints Are Broken: UpdateException
Exceptions Thrown by Broken Constraints in the Database
Automatically Rolling Back SaveChanges When an UpdateException Occurs
ObjectStateEntries Returned by Object Services Exceptions
General Entity Exceptions That May Occur When Executing Queries or Commands
InvalidOperationExceptions
Exceptions When Multiple Parties Edit Data Concurrently
Handling Concurrency Conflicts
Understanding Optimistic Concurrency Options in the Entity Framework
Ignoring Concurrency Conflicts
Forcing the User’s Data to the Server (ClientWins)
Refreshing the User’s Data with Server Data (StoreWins)
Determining the Scope of Changes
Using rowversion for Concurrency Checks
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
Defining a stored procedure to perform concurrency checking
Handling OptimisticConcurrencyExceptions
Using ObjectContext.Refresh
Using ClientWins Refresh
Using StoreWins Refresh
Refreshing Collections of Entities
Refreshing Related Entities in a Graph
Rewinding and Starting Again, and Maybe Again After That
What If a Relationship, But No Scalar Properties, Changes?
Reporting an Exception
Handling Concurrency Exceptions at a Lower Level
Handling Granular Exceptions Without User Intervention
Handling Multiple Conflicts
Separating the good from the bad
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
EntityCollection navigation properties
EntityReference 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
The IEntityWithKey Interface
The IEntityWithChangeTracker Interface
An EntityState property
The IEntityWithRelationships Interface
Working with the IPOCO-Enabled Objects
Custom Class Assemblies and Entity Data Model Files
Accessing the Model Files When They Are Not in a Referenced Assembly
Summary
20. Using the Entity Framework in n-Tier Client-Side Applications
Thinking in Layers
Organizing Your 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
Creating an IsDirty Property for the ObjectContext
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
Precompiling a frequently used query
Some decisions that drove the design of the GetCustomerwithRelatedData method
Converting a noncustomer to a customer
Supplying Additional Lists for UI Drop-Downs
Choosing between complete entities and narrower types for lists
Saving Changes
Rolling Back User Changes
Considering in-memory rollbacks
Keeping it simple: Rolling back from the database if you can
Using the DataBridge Class for Data Binding in a Master/Detail Form
Using BindingSourceControls with the DataBridge
Instantiating the DataBridge Class in the Form
Populating the Form with an Entity and Its Related Data
Consuming the Pick Lists in the Form
Deleting from Grids When EntityCollections and Referential Constraints Are Involved
Deleting children from a grid is easier when the child has a composite key
Deleting child entities in a grid when no referential constraint exists in the CSDL
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
Using EntityObjects in Read-Only Web Pages
Exploring Options for Updating Entities in an ASP.NET Application
Single or batch updates?
Persist entities or use independent values?
Evaluating ASP.NET’s State Solutions Against the Entity Framework
View State
Application cache and session state
Introducing ASP.NET’s ObjectDataSource Control
Why ObjectDataSource?
ObjectDataSource Enforces Its Rules on Your Objects
How the ObjectDataSource Gets Data into and out of the Data-Binding Controls
Designing Object Provider Classes to Be Used with an ObjectDataSource
Creating the CustomerProvider Class
Creating the AddressProvider Class
Creating the ReservationsProvider Class
Providing Reusable, Cached Reference Lists
Wiring Up the Provider Classes to ObjectDataSource Controls
Using the ObjectDataSource Wizard to Perform the Initial Wiring to the Provider Classes
Tweaking ObjectDataSource Properties to Work with Entities
Getting the object to the entity provider
Providing original and current values for updates
Using ObjectDataSource Events to Solve Problems That Are Particular to Entities
Inserting and updating entities that contain EntityReferences
Editing EntityReference navigation properties
Updating EntityReference navigation properties
Inserting records with EntityReference properties
Understanding Why We Didn’t Use Object Graphs in This Business Layer
Database Hits Versus Very Busy Memory
Summary
22. Implementing a Smarter WCF Service for Working with Entities
Will Your Client Agree to Your Data Contract?
Shipping DTOs, Not EntityObjects
Building a Data Transfer Object to Take the Place of an Entity Object
Replacing EntityReference navigation properties
Replacing EntityCollection navigation properties
Creating EntityState Properties That Do Not Rely on ObjectContext
The EntityStateLocal Enums and Interface
Implementing the IEntityStateLocal Interface in the DTO Classes
Implementing the IEntityStateLocal Interface in the Entity Classes
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
Rules for the Client to Follow
Building a Business Layer Between the UI and the Services
What’s in These Business Classes?
The class constructor
The property changed event
The Initialize method
Calling the Service Operations from the Business Layer
Testing It All with a Simple Console Application
Summary
23. The Entity Framework, Today and Tomorrow
What About Building Reports with the Entity Framework?
Major Differences Between the Entity Framework and LINQ to SQL
The future of LINQ to SQL
Migrating LINQ to SQL to the Entity Framework
Extensions, Samples, and Solutions from Microsoft
Extensions and APIs
EFExtensions
POCO Adapter for version 1
Entity Framework Lazy Loading
eSqlBlast
Samples
Entity Framework Query Samples
Sample EDMX Code Generator
Entity Framework Sample Provider
Learning Tools
Entity Framework v.Next
The Transparent Design Process for the Next Version
Blogs, Forums, and Other Resources
A. Entity Framework Assemblies and Namespaces
Unpacking the Entity Framework Files
Exploring the Namespaces
Existing Namespaces That Have New Classes and Functionality
New Namespaces
Index
About the Author
Colophon
Copyright
Search in book...
Toggle Font Controls
Playlists
Add To
Create new playlist
Name your new playlist
Playlist description (optional)
Cancel
Create playlist
Sign In
Email address
Password
Forgot Password?
Create account
Login
or
Continue with Facebook
Continue with Google
Sign Up
Full Name
Email address
Confirm Email Address
Password
Login
Create account
or
Continue with Facebook
Continue with Google
Prev
Previous Chapter
Index
Next
Next Chapter
Index
C
C#,
Exploring EDM Queries in Greater Depth
,
VB and C# syntax differences
,
Anonymous types
,
Implicitly typed local variables
,
Implicit and explicit anonymous type creation
,
Grouping
,
Naming Properties When Grouping
,
Chaining Aggregates
,
Implementing the property-level PropertyChanged and PropertyChanging methods
,
Implementing the class-level PropertyChanging and PropertyChanged events
,
Specifying or Excluding Derived Types in Queries
,
Forcing an ObjectContext to Use Its Own Thread
,
Setting Up the Project and Code File
,
Scalar Properties
anonymous types in version 3.0,
Anonymous types
auto-implemented properties,
Scalar Properties
direct type comparison,
Specifying or Excluding Derived Types in Queries
example queries,
Exploring EDM Queries in Greater Depth
grouping,
Grouping
,
Naming Properties When Grouping
,
Chaining Aggregates
combining aggregates in C# LINQ,
Chaining Aggregates
INTO clause, specifying group name,
Naming Properties When Grouping
implementing PropertyChanged and PropertyChanging events,
Implementing the class-level PropertyChanging and PropertyChanged events
implicitly typed local variables,
Implicitly typed local variables
lock keyword,
Forcing an ObjectContext to Use Its Own Thread
naming anonymous types,
Implicit and explicit anonymous type creation
ObjectStateEntry visualizer,
Setting Up the Project and Code File
partial method implementation,
Implementing the property-level PropertyChanged and PropertyChanging methods
projections,
VB and C# syntax differences
cached queries,
Filtering based on group properties
caching,
Query Plan Caching for Entity SQL
,
Application cache and session state
application cache,
Application cache and session state
query plan caching for Entity SQL,
Query Plan Caching for Entity SQL
canonical functions (Entity SQL),
Entity SQL canonical functions
cascading deletes,
How Did the Entity Data Model Wizard Create the Association?
,
Deletes and Cascading Deletes
,
Cascading deletes in the database
,
Cascading deletes in the EDM
,
Recommendation: Cascade in both the model and the database, or in neither
in the database,
Cascading deletes in the database
in the EDM,
Cascading deletes in the EDM
recommendation for use in both EDM and database, or neither,
Recommendation: Cascade in both the model and the database, or in neither
chaining methods,
Chaining methods
change tracking,
Change Tracking
,
Challenges with Change Tracking Distributed Applications
,
How ObjectContext Manages Entities
,
Change Tracking
,
The insert and update web methods
,
The IEntityWithChangeTracker Interface
IEntityWithChangeTracker interface,
The IEntityWithChangeTracker Interface
problems in distributed applications,
Challenges with Change Tracking Distributed Applications
problems in multi-tiered applications,
The insert and update web methods
remembering original values and tracking changes,
How ObjectContext Manages Entities
Changing/Changed methods,
Customizable Methods
,
The On[Property]Changed and On[Property]Changing Methods
,
Implementing the property-level PropertyChanged and PropertyChanging methods
,
The EntityObject.PropertyChanging and EntityObject.PropertyChanged Events
,
The order of the Changing/Changed events
,
Event parameters
,
Implementing the class-level PropertyChanging and PropertyChanged events
class level,
The EntityObject.PropertyChanging and EntityObject.PropertyChanged Events
,
Event parameters
,
Implementing the class-level PropertyChanging and PropertyChanged events
event parameters,
Event parameters
implementing,
Implementing the class-level PropertyChanging and PropertyChanged events
order of events,
The order of the Changing/Changed events
property level,
The On[Property]Changed and On[Property]Changing Methods
,
Implementing the property-level PropertyChanged and PropertyChanging methods
implementing,
Implementing the property-level PropertyChanged and PropertyChanging methods
checksum in data store, concurrency checks on,
Concurrency Checking on a Checksum in the Data Store
class constructor, WCF service client application,
The class constructor
classes,
The Entity in “Entity Framework”
,
Code Generation from EDM to Classes
,
Where Did the Context and Classes Come from?
,
Entity Objects
,
Entity Objects
,
Object Services Supports Custom Classes
,
Partial Classes
,
Using Your Own Custom Classes
–
Summary
,
Mapping Classes to the Entity Data Model
–
Querying Using the Custom Classes
,
Resolving Conflicts Between Custom Classes and Designer-Generated Classes
,
Querying Using the Custom Classes
,
Implementing the IPOCO Interfaces
–
Working with the IPOCO-Enabled Objects
,
Custom Class Assemblies and Entity Data Model Files
,
Building a Data Transfer Object to Take the Place of an Entity Object
automatically created from the EDM,
Code Generation from EDM to Classes
class diagram for entities (example),
The Entity in “Entity Framework”
custom,
Object Services Supports Custom Classes
,
Using Your Own Custom Classes
–
Summary
,
Mapping Classes to the Entity Data Model
–
Querying Using the Custom Classes
,
Resolving Conflicts Between Custom Classes and Designer-Generated Classes
,
Querying Using the Custom Classes
,
Implementing the IPOCO Interfaces
–
Working with the IPOCO-Enabled Objects
,
Custom Class Assemblies and Entity Data Model Files
assemblies and EDM files,
Custom Class Assemblies and Entity Data Model Files
conflicts with Designer-generated classes,
Resolving Conflicts Between Custom Classes and Designer-Generated Classes
implementing IPOCO interfaces,
Implementing the IPOCO Interfaces
–
Working with the IPOCO-Enabled Objects
mapping to Entity Data Model,
Mapping Classes to the Entity Data Model
–
Querying Using the Custom Classes
querying with,
Querying Using the Custom Classes
support by Object Services,
Object Services Supports Custom Classes
entity,
Entity Objects
,
Entity Objects
(see also entity objects)
in LINQ to Entities queries example,
Where Did the Context and Classes Come from?
marking as DataContract,
Building a Data Transfer Object to Take the Place of an Entity Object
partial classes, Entity Framework and,
Partial Classes
client applications,
Building a Client That Is Ignorant of the Entity Framework
,
Building the Client Application
–
The client-side Customer versus the server-side Customer
,
Setting up the client project and the proxy to the service
,
Adding methods to interact with the web service
,
Designing the form
,
The client-side Customer versus the server-side Customer
,
Building the Client to Consume the WCF Service
–
Peeking under the covers
,
Editing the configuration for the web service client
,
Adding functionality to view the reservations
,
Finishing the form
,
Adding and deleting the reservations
,
Adding and deleting the reservations
,
Running the application and saving your changes
,
Using the Entity Framework in n-Tier Client-Side Applications
,
Thinking in Layers
,
Implementing the Client That Will Use the WCF Service
–
Testing It All with a Simple Console Application
,
Rules for the Client to Follow
,
Building a Business Layer Between the UI and the Services
,
What’s in These Business Classes?
–
Calling the Service Operations from the Business Layer
,
Calling the Service Operations from the Business Layer
–
Testing It All with a Simple Console Application
(see also n-tier client-side applications)
ASMX Web Service client,
Building the Client Application
–
The client-side Customer versus the server-side Customer
,
Setting up the client project and the proxy to the service
,
Adding methods to interact with the web service
,
Designing the form
,
The client-side Customer versus the server-side Customer
designing form,
Designing the form
ignorance of Entity Framework,
The client-side Customer versus the server-side Customer
methods to interact with service,
Adding methods to interact with the web service
reference to service and proxies,
Setting up the client project and the proxy to the service
client for WCF service,
Building the Client to Consume the WCF Service
–
Peeking under the covers
,
Editing the configuration for the web service client
,
Adding functionality to view the reservations
,
Finishing the form
,
Adding and deleting the reservations
,
Adding and deleting the reservations
,
Running the application and saving your changes
,
Implementing the Client That Will Use the WCF Service
–
Testing It All with a Simple Console Application
,
Rules for the Client to Follow
,
Building a Business Layer Between the UI and the Services
,
What’s in These Business Classes?
–
Calling the Service Operations from the Business Layer
,
Calling the Service Operations from the Business Layer
–
Testing It All with a Simple Console Application
adding and deleting reservations,
Adding and deleting the reservations
adding functionality to view reservations,
Adding functionality to view the reservations
business layer between UI and services,
Building a Business Layer Between the UI and the Services
calling service operations from business layer,
Calling the Service Operations from the Business Layer
–
Testing It All with a Simple Console Application
content of business classes,
What’s in These Business Classes?
–
Calling the Service Operations from the Business Layer
editng configuration,
Editing the configuration for the web service client
finishing the form,
Finishing the form
no EntityKey or EntityReference in client,
Adding and deleting the reservations
rules for client,
Rules for the Client to Follow
running application and saving changes,
Running the application and saving your changes
Entity Framework and,
Building a Client That Is Ignorant of the Entity Framework
using Entity Framework, basic architecture for,
Thinking in Layers
ClientWins,
Forcing the User’s Data to the Server (ClientWins)
,
Using ObjectContext.Refresh
,
Using ClientWins Refresh
,
Refreshing Collections of Entities
ObjectContext.Refresh method,
Using ClientWins Refresh
,
Refreshing Collections of Entities
refreshing set of entities,
Refreshing Collections of Entities
RefreshMode value,
Using ObjectContext.Refresh
Code Gallery project,
Extensions, Samples, and Solutions from Microsoft
,
Samples
samples provided by,
Samples
code generation,
Code Generation from EDM to Classes
,
Custom Code Generation
custom,
Custom Code Generation
default,
Code Generation from EDM to Classes
Collection class, IQueryable and IEnumerable versus,
ObjectQuery and LINQ to Entities
CollectionChangeAction enumeration,
Event arguments
CollectionChangeEventArgs, AssociationChanged event,
Event arguments
collections, ObservableCollection object,
A few WPF tricks for a more interactive ListBox
ComboBox controls,
Binding the ComboBox controls to the ListBox and to the data
,
Editing Trip Entities and Their Related Data
binding to ListBox and to data in WPF,
Binding the ComboBox controls to the ListBox and to the data
SelectionChanged event,
Editing Trip Entities and Their Related Data
command execution exceptions, SaveChanges method,
SaveChanges Command Execution Exceptions
command trees,
Query Processing
,
From a LINQ to Entities query to a command tree
,
From Entity SQL and query builder methods to a command tree
,
How EntityClient turns command trees into store commands
conversion by entity client to store commands,
How EntityClient turns command trees into store commands
conversion of Entity SQL and query builder methods to,
From Entity SQL and query builder methods to a command tree
query processing from LINQ to Entities query to,
From a LINQ to Entities query to a command tree
CommandExecutor class, building (example),
Building the CommandExecutor Class
–
Building the CommandExecutor Class
compilation of queries,
Reducing the Cost of Query Compilation
,
The EDM Generator for Precompiled Views (and More)
,
Query Compilation Exceptions
,
Precompiling a frequently used query
EDM Generator for precompiled views,
The EDM Generator for Precompiled Views (and More)
exceptions,
Query Compilation Exceptions
precompiling frequently used query,
Precompiling a frequently used query
reducing cost of,
Reducing the Cost of Query Compilation
compiled queries,
Filtering based on group properties
CompiledQuery class, Compile method,
LINQ to Entities compiled queries
complex types,
Creating Complex Types to Encapsulate Sets of Properties
–
Removing the Complex Types from the Model
,
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
,
ASP.NET EntityDataSource
,
Data Binding Complex Types in ASP.NET Without the EntityDataSource
–
Windows Forms DataSource and Complex Types
,
Windows Forms DataSource and Complex Types
,
Removing the Complex Types from the Model
,
Getting ComplexType Properties Out of ObjectStateEntry
ComplexObjects rather than EntityObjects,
Complex Types Are Not EntityObjects
data binding,
Complex Types in Data-Binding Scenarios
,
ASP.NET EntityDataSource
,
Data Binding Complex Types in ASP.NET Without the EntityDataSource
–
Windows Forms DataSource and Complex Types
using EntityDataSource,
ASP.NET EntityDataSource
without EntityDataSource,
Data Binding Complex Types in ASP.NET Without the EntityDataSource
–
Windows Forms DataSource and Complex Types
defining,
Defining a Complex Type
EDM designer and,
Complex Types and the EDM Designer
mapping entities with,
Mapping Entities with Complex Types
properties of complex type, getting from ObjectStateEntry,
Getting ComplexType Properties Out of ObjectStateEntry
querying, creating, and saving entities with,
Using Complex Types
removing from the EDM,
Removing the Complex Types from the Model
replacing properties with,
Replacing Properties with a Complex Type
Windows Forms DataSource and,
Windows Forms DataSource and Complex Types
ComplexObject,
Complex Types Are Not EntityObjects
composable queries,
Specifying the control variable
composition versus inheritance,
Creating New Derived Entities When the Base Entity Already Exists
Conceptual Schema Definition Language,
The Three Parts of the Model
(see CSDL)
concurrency,
Concurrency Management
,
Optimistic concurrency
,
ConcurrencyMode
,
OptimisticConcurrencyException
,
Exceptions When Multiple Parties Edit Data Concurrently
,
Handling Concurrency Conflicts
,
Understanding Optimistic Concurrency Options in the Entity Framework
,
Using rowversion for Concurrency Checks
,
Using rowversion for Concurrency Checks
,
Handling Concurrency Exceptions at a Lower Level
,
Handling Granular Exceptions Without User Intervention
,
Handling Multiple Conflicts
,
Handling Exceptions When Transactions Are Your Own
(see also optimistic concurrency)
checking using rowversion field,
Using rowversion for Concurrency Checks
ConcurrencyMode attribute,
ConcurrencyMode
exceptions when multiple parties edit data concurrently,
Exceptions When Multiple Parties Edit Data Concurrently
handling conflicts in,
Handling Concurrency Conflicts
handling exceptions for your transactions,
Handling Exceptions When Transactions Are Your Own
handling of low-level exceptions,
Handling Concurrency Exceptions at a Lower Level
,
Handling Granular Exceptions Without User Intervention
,
Handling Multiple Conflicts
handling multiple conflicts,
Handling Multiple Conflicts
handling without user intervention,
Handling Granular Exceptions Without User Intervention
optimistic concurrency,
Optimistic concurrency
optimistic concurrency options in Entity Framework,
Understanding Optimistic Concurrency Options in the Entity Framework
OptimisticConcurrencyException,
OptimisticConcurrencyException
ConcurrencyMode property,
Determining the Scope of Changes
,
Flagging a Property for Concurrency Checking
,
How the Entity Framework Uses the ConcurrencyMode Property
,
Concurrency Checks and Inherited Types
derived types,
Concurrency Checks and Inherited Types
how Entity Framework uses it,
How the Entity Framework Uses the ConcurrencyMode Property
conditional mapping,
Using Conditional Mapping to Filter Entity Mappings
–
Removing the conditional mapping from Activity and re-creating the Category property
,
Creating a Conditional Mapping for the Activity Entity
,
Testing the Conditional Mapping
,
Removing the conditional mapping from Activity and re-creating the Category property
creating for an entity,
Creating a Conditional Mapping for the Activity Entity
querying, creating, and saving conditionally mapped entities,
Testing the Conditional Mapping
removing,
Removing the conditional mapping from Activity and re-creating the Category property
ConfigurationManager class,
Using the EntityConnectionStringBuilder Class
connection pooling,
What About Connection Pooling?
Connection property, ObjectContext,
Connection versus Connection.StoreConnection
connection strings,
EntityConnection and the Connection String
,
ObjectContext.Connection
,
EntityConnectionString Exceptions
,
Handling Connection String Exceptions
,
Accessing the Model Files When They Are Not in a Referenced Assembly
ConnectionString to find EDM files in file path,
Accessing the Model Files When They Are Not in a Referenced Assembly
EntityConnection and,
EntityConnection and the Connection String
EntityConnectionString exceptions,
EntityConnectionString Exceptions
handling exceptions in,
Handling Connection String Exceptions
specifying EntityConnection string to use for context,
ObjectContext.Connection
connections,
Making It Real: Connections, Transactions, Performance, and More
–
What About Connection Pooling?
,
EntityConnection and Database Connections in the Entity Framework
,
Manually opening and closing connections
,
Default behavior 1: Many calls on a single connection
,
Default behavior 2: Multiple connections
,
Forcing an explicit connection
,
Taking Control of How Store Connections Are Disposed
,
Protecting Data from Connection Piggybacks
disposal of store connections,
Taking Control of How Store Connections Are Disposed
EntityConnection and database connections,
EntityConnection and Database Connections in the Entity Framework
opening and closing Entity and database connections,
Manually opening and closing connections
,
Default behavior 1: Many calls on a single connection
,
Default behavior 2: Multiple connections
,
Forcing an explicit connection
forcing explicit connection,
Forcing an explicit connection
manually,
Manually opening and closing connections
many calls on single connection,
Default behavior 1: Many calls on a single connection
multiple connections,
Default behavior 2: Multiple connections
protecting data from connection piggybacks,
Protecting Data from Connection Piggybacks
constraints,
ReferentialConstraint
,
How Did the Entity Data Model Wizard Create the Association?
,
Referential Integrity and Constraints
,
Constraints that are not checked until they hit the database
,
Constraints that the Entity Framework checks when SaveChanges is called
,
Deletes and Cascading Deletes
,
Model and Mapping Constraints Are Broken: UpdateException
,
Exceptions Thrown by Broken Constraints in the Database
,
Deleting from Grids When EntityCollections and Referential Constraints Are Involved
–
Deleting child entities in a grid when no referential constraint exists in the CSDL
,
Deleting children from a grid is easier when the child has a composite key
association with a constraint in CSDL,
Deleting children from a grid is easier when the child has a composite key
checked by Entity Framework in calls to SaveChanges,
Constraints that the Entity Framework checks when SaveChanges is called
checks deferred to database,
Constraints that are not checked until they hit the database
database constraints enforcing referential integrity, cascading deletes and,
Deletes and Cascading Deletes
deletions from grids with referential constraints involved,
Deleting from Grids When EntityCollections and Referential Constraints Are Involved
–
Deleting child entities in a grid when no referential constraint exists in the CSDL
exceptions thrown by broken constraints in database,
Exceptions Thrown by Broken Constraints in the Database
model and mapping constraints broken, UpdateException,
Model and Mapping Constraints Are Broken: UpdateException
referential integrity and,
Referential Integrity and Constraints
ReferentialConstraint element in the SSDL,
ReferentialConstraint
context,
Where Did the Context and Classes Come from?
,
Where Did the Context and Classes Come from?
,
Using your own context
,
EntityDataSource Context Events
(see also ObjectContext class)
EntityDataSource context events,
EntityDataSource Context Events
using your own for EntityDataSource,
Using your own context
ContextCreated event, EntityDataSource,
EntityDataSource Context Events
ContextCreating event, EntityDataSource,
Using your own context
,
EntityDataSource Context Events
ContextDisposing event, EntityDataSource,
EntityDataSource Context Events
control variable,
LINQ to Entities Queries
,
Entity SQL
,
ObjectQuery’s Query Builder Methods
,
Specifying the control variable
default alias for,
ObjectQuery’s Query Builder Methods
specifying,
Specifying the control variable
ControlState, ASP.NET page,
EntityDataSource and ViewState
Create factory method, overloading,
Overloading Context and Entity Methods
CreateInstance method,
Creating a New Entity with CreateInstance
CreateQuery method,
Using Include with an ObjectQuery
,
A Better Understanding of Query Builder Methods
,
Query Execution with the ToList or ToArray Method
Entity SQL expression as parameter,
A Better Understanding of Query Builder Methods
ToList appended to, focing query execution,
Query Execution with the ToList or ToArray Method
using Include method with,
Using Include with an ObjectQuery
CreateSourceQuery method, enhancing deferred loading,
Using CreateSourceQuery to Enhance Deferred Loading
CSDL (Conceptual Schema Definition Language),
The Three Parts of the Model
,
CSDL: The Conceptual Schema
–
Where Are the Foreign Keys?
,
Schema
,
EntityContainer
,
EntitySet
,
EntityType
,
Associations
,
AssociationSet
,
NavigationProperty
,
Navigation Properties That Return Collections
,
Where Are the Foreign Keys?
,
The EDM Designer’s Model Browser
,
Defining a Complex Type
,
Constraints that are not checked until they hit the database
associations,
Associations
AssociationSet objects,
AssociationSet
complex type defined in,
Defining a Complex Type
constraints in,
Constraints that are not checked until they hit the database
EntityContainer class,
EntityContainer
EntitySet class,
EntitySet
EntityType data type,
EntityType
foreign keys, missing,
Where Are the Foreign Keys?
navigation properties returning collections,
Navigation Properties That Return Collections
NavigationProperty,
NavigationProperty
schema,
Schema
viewing in Designer’s Model Browser,
The EDM Designer’s Model Browser
CurrentValueRecord.DataRecordInfo,
CurrentValueRecord.DataRecordInfo
CurrentValueRecord.SetBoolean,
Modifying Values with ObjectStateManager
CurrentValues property, ObjectStateEntry,
State Management and ObjectStateEntry
,
ObjectContext.Attach
,
CurrentValues and OriginalValues
,
Reading the OriginalValues and CurrentValues of an ObjectStateEntry
,
Modifying Values with ObjectStateManager
modifying values with ObjectStateManager,
Modifying Values with ObjectStateManager
reading with visualizer tool,
Reading the OriginalValues and CurrentValues of an ObjectStateEntry
CurrentValues, ObjectStateEntry,
CurrentValues and OriginalValues
reading,
CurrentValues and OriginalValues
customization of entities,
Customizing Entities
–
Summary
,
Partial Classes
,
Customizable Methods
–
Using PropertyChanged to Calculate Database-Computed Columns Locally
,
Customizable Event Handlers
–
Other Opportunities for Customization
,
Custom Properties
–
Custom Properties That Perform Calculations on Child Collections
,
Overloading Context and Entity Methods
,
Custom Code Generation
,
Creating Common Methods or Properties for All Entities
creating common methods or properties for all entities,
Creating Common Methods or Properties for All Entities
custom code generation,
Custom Code Generation
event handlers,
Customizable Event Handlers
–
Other Opportunities for Customization
methods,
Customizable Methods
–
Using PropertyChanged to Calculate Database-Computed Columns Locally
overloading context and entity methods,
Overloading Context and Entity Methods
partial classes,
Partial Classes
properties,
Custom Properties
–
Custom Properties That Perform Calculations on Child Collections
Add Highlight
No Comment
..................Content has been hidden....................
You can't read the all page of ebook, please click
here
login for view all page.
Day Mode
Cloud Mode
Night Mode
Reset