You are previewing Microsoft ADO.NET Entity Framework Step by Step.
O'Reilly logo
Microsoft ADO.NET Entity Framework Step by Step

Book Description

Your hands-on guide to Entity Framework fundamentals

Expand your expertise—and teach yourself the fundamentals of the Microsoft ADO.NET Entity Framework 5. If you have previous programming experience but are new to the Entity Framework, this tutorial delivers the step-by-step guidance and coding exercises you need to master core topics and techniques.

Discover how to:

  • Access data in a managed way—using minimal code

  • Apply three workflows supported by the Entity Framework

  • Perform essential tasks with full automation in place

  • Manipulate data with both LINQ and Entity SQL

  • Create examples that rely on Table-Valued Functions

  • Determine the remedies for Entity-specific exceptions

  • Explore the use of optimistic and pessimistic concurrency

  • Define mappings between your applications and data sources

  • Table of Contents

    1. Microsoft ADO.NET Entity Framework Step by Step
    2. Dedication
    3. A Note Regarding Supplemental Files
    4. Introduction
      1. Who should read this book
        1. Assumptions
      2. Who should not read this book
      3. Organization of this book
        1. Finding your best starting point in this book
      4. Conventions and features in this book
      5. System requirements
      6. Code samples
        1. Installing the code samples
        2. Using the code samples
      7. Acknowledgments
      8. Errata & book support
      9. We want to hear from you
      10. Stay in touch
    5. I. Introducing the Entity Framework
      1. 1. Getting to know the Entity Framework
        1. Defining an entity
        2. Understanding the Entity Framework elements
          1. Considering the conceptual model
          2. Considering the storage model
          3. Considering the model mappings
        3. Introducing the Entity Framework files
          1. Viewing the Conceptual Schema Definition Language file
          2. Viewing the Store Schema Definition Language file
          3. Viewing the Mapping Specification Language file
        4. Developing a simple Entity Framework example
          1. Starting the Entity Data Model Wizard
          2. Using the Entity Data Model Designer
          3. Working with the mapping details
          4. Using the resulting framework to display data
        5. Getting started with the Entity Framework
        6. Chapter 1 quick reference
      2. 2. Looking more closely at queries
        1. Defining a basic query
          1. Creating the model
          2. Working with enumerations
          3. Obtaining an application data source
          4. Creating the test application
          5. Running the basic query
        2. Creating specific queries
          1. Using literals
          2. Using operators, properties, and methods
        3. Combining and summarizing data
        4. Grouping data
        5. Getting started with the Entity Framework
        6. Chapter 2 quick reference
      3. 3. Choosing a workflow
        1. Understanding the code-first workflow
        2. Understanding the model-first workflow
        3. Understanding the database-first workflow
        4. Defining the workflow choices
        5. Creating a code-first example
          1. Creating a project
          2. Defining the initial classes
          3. Adding Entity Framework 5 support
          4. Creating a code-first context
        6. Adding a record
          1. Viewing the results
        7. Creating a model-first example
          1. Defining the database model
          2. Adding a record and viewing the results
        8. Creating a database-first example
          1. Reverse engineering the database model
          2. Adding a record and comparing results
        9. Getting started with the Entity Framework
        10. Chapter 3 quick reference
    6. II. Completing basic tasks
      1. 4. Generating and using objects
        1. Understanding the Entity objects
          1. Considering object services
          2. Considering the base classes
          3. Working with an EntityCollection
          4. Understanding the role of Entity SQL
        2. Making queries using objects
          1. Considering the role of lambda expressions
          2. Creating a basic query using Entity SQL
          3. Creating a basic query using LINQ
        3. Modifying data using objects
          1. Adding the forms
          2. Adding purchases
          3. Updating purchases
          4. Deleting purchases
        4. Working with Query Builder methods
        5. Getting started with the Entity Framework
        6. Chapter 4 quick reference
      2. 5. Performing essential tasks
        1. Defining the essential tasks
          1. Viewing the data
          2. Saving changes
          3. Inserting new values
          4. Deleting old values
        2. Creating a master/detail form
          1. Creating the data source
          2. Configuring the data source
          3. Adding and configuring the controls
          4. Testing the result
        3. Getting started with the Entity Framework
        4. Chapter 5 quick reference
    7. III. Manipulating data using the Entity Framework
      1. 6. Manipulating data using LINQ
        1. Introducing LINQ to Entities
          1. Considering the LINQ to Entities provider
          2. Developing LINQ to Entities queries
          3. Defining the LINQ to Entities essential keywords
          4. Defining the LINQ to Entities operators
            1. Performing filtering and projection
            2. Performing joins
            3. Creating a set
            4. Ordering the output
            5. Grouping the output
            6. Performing aggregation
            7. Interacting with type
            8. Paging the output
            9. Summarizing the LINQ operators
        2. Understanding LINQ compilation
          1. Following an IQueryable sequence
          2. Following a List sequence
        3. Using entity and database functions
          1. Creating the function
          2. Accessing the function
        4. Getting started with the Entity Framework
        5. Chapter 6 quick reference
      2. 7. Manipulating data using Entity SQL
        1. Understanding Entity SQL
          1. Considering the Entity SQL data flow
          2. Defining the Entity SQL components
            1. SELECT VALUE and SELECT
            2. Literals
              1. String
              2. DateTime and Time
              3. Integer, real, and decimal
              4. Other
            3. Type constructors
              1. ROW
              2. Collection
              3. Named type
            4. References
            5. Functions
              1. User-defined functions
              2. Aggregate functions
              3. Working with overloaded functions
            6. Namespaces
            7. Paging
            8. Grouping
            9. Navigation
            10. CASE expression
        2. Selecting data
        3. Working with literals in Entity SQL
          1. Using the standard literals
          2. Adding some additional data
          3. Using a date or time literal
          4. Interacting with a decimal literal
        4. Ordering data
        5. Grouping data
        6. Getting started with the Entity Framework
        7. Chapter 7 quick reference
      3. 8. Interaction with stored procedures
        1. Understanding stored procedures
        2. Adding stored procedures to your model
          1. Defining the stored procedure using Server Explorer
          2. Testing the stored procedure
          3. Updating the model
          4. Modifying a stored procedure
            1. Performing the required update
            2. Retesting the stored procedure
            3. Adding the update to the model
        3. Building an application using stored procedures
        4. Creating a basic stored procedure example
        5. Getting started with the Entity Framework
        6. Chapter 8 quick reference
      4. 9. Interaction with views
        1. Understanding views
        2. Adding views to your model
          1. Defining views using Server Explorer
          2. Testing the view
          3. Updating the model
        3. Creating a basic view example
        4. Making views writable
        5. Getting started with the Entity Framework
        6. Chapter 9 quick reference
      5. 10. Interaction with Table-Valued Functions
        1. Understanding TVFs
          1. Comparing TVFs to views
          2. Comparing TVFs to stored procedures
          3. Defining the storage layer
          4. Defining the mapping layer
          5. Defining the conceptual layer
          6. Defining the object layer
        2. Adding TVFs to your model
          1. Defining the TVF using Server Explorer
          2. Testing the TVF
          3. Updating the model
        3. Calling a TVF using Entity SQL
        4. Calling a TVF using LINQ
        5. Mapping a TVF to an entity type collection
        6. Getting started with the Entity Framework
        7. Chapter 10 quick reference
    8. IV. Overcoming entity errors
      1. 11. Dealing with exceptions
        1. Understanding exceptions
        2. Considering exception sources
          1. Dealing with the System.Data.EntityException
          2. Working through System.Data namespace exceptions
          3. Working through System.Data.Common namespace exceptions
          4. Working through System.Data.Linq namespace exceptions
        3. Handling connection string exceptions
          1. Seeing the connection string problem
          2. Creating code for the connection string problem
          3. Adding another layer of exception handling
        4. Dealing with query exceptions
        5. Dealing with other data exception types
        6. Understanding concurrency exceptions
        7. Getting started with the Entity Framework
        8. Chapter 11 quick reference
      2. 12. Overcoming concurrency issues
        1. Visualizing database concurrency issues
        2. Considering optimistic concurrency problems
          1. Rejecting the change
          2. Performing a partial update
          3. Obtaining user input
          4. Ignoring concurrency issues completely
          5. Performing a forced update
        3. Implementing optimistic concurrency in an application
          1. Developing the test environment
          2. Testing the default concurrency
          3. Coding for field changes
          4. Using field-specific concurrency
          5. Using row-version concurrency
        4. Considering pessimistic concurrency issues
        5. Getting started with the Entity Framework
        6. Chapter 12 quick reference
      3. 13. Handling performance problems
        1. Understanding performance issue sources
          1. Considering the layers
          2. Retrieving too many records
          3. Using the local cache
          4. Relying on pregenerated views
          5. Relying on precompiled queries
          6. Disabling change tracking
          7. Choosing between lazy loading and eager loading
        2. Viewing performance issues
          1. Direct query viewing
            1. Working with LINQ to Entities
            2. Working with Entity SQL
          2. Using third-party products
        3. Defining the performance triangle
          1. Considering the effects of raw speed
          2. Considering the effects of security
            1. Considering the connection
            2. Keeping memory secure
            3. Interacting with users
            4. Maintaining configuration integrity
          3. Considering how raw speed and security affect reliability
        4. Using multithreading as an aid to speed
        5. Getting started with the Entity Framework
        6. Chapter 13 quick reference
    9. V. Advanced management techniques
      1. 14. Creating custom entities
        1. Developing POCO classes
          1. Configuring the model
          2. Adding the classes
          3. Creating an ObjectContext class to interact with the POCO classes
          4. Testing the POCO application
          5. Creating a DbContext class to interact with the POCO classes
          6. Creating the classes in a different project
            1. Using automatic generation
            2. Using manual generation
        2. Creating and using event handlers
          1. Handling ObjectContext events
          2. Creating and handling custom events
        3. Creating custom methods
        4. Creating custom properties
        5. Getting started with the Entity Framework
        6. Chapter 14 quick reference
      2. 15. Mapping data types to properties
        1. Understanding mapping automation configuration
          1. Configuring properties
          2. Changing property mapping
          3. Filtering the data
        2. Working with standard data types
          1. Considering the standard data type mapping scenarios
          2. Creating the Rewards3 database
          3. Performing standard data type mapping
        3. Working with enumerated data types
        4. Working with complex data types
        5. Working with geography and geometry spatial data types
        6. Getting started with the Entity Framework
        7. Chapter 15 quick reference
      3. 16. Performing advanced management tasks
        1. Developing multiple diagrams for a model
          1. Creating the new diagram
          2. Configuring the diagram appearance
            1. Using a grid
            2. Color-coding the entities
            3. Adding type to the display
            4. Exporting the diagram as an image
        2. Performing batch imports of stored procedures and functions
        3. Mapping a stored procedure that returns multiple result sets
          1. Creating the stored procedure
          2. Using the code-access technique
          3. Using the EDMX modification technique
        4. Creating entities with inheritance
          1. Creating the Rewards4 database
          2. Using inheritance with the model-first workflow
          3. Using inheritance with the code-first workflow
        5. Controlling context actions for automatically generated classes
        6. Getting started with the Entity Framework
        7. Chapter 16 quick reference
    10. A. About the Author
    11. Index
    12. About the Author
    13. Copyright