Entity Framework 6 Recipes, Second Edition

Book description

Entity Framework 6 Recipes provides an exhaustive collection of ready-to-use code solutions for Entity Framework, Microsoft's model-centric, data-access platform for the .NET Framework and ASP.NET development. With this book, you will learn the core concepts of Entity Framework through a broad range of clear and concise solutions to everyday data access tasks. Armed with this experience, you will be ready to dive deep into Entity Framework, experiment with new approaches, and develop ways to solve even the most difficult data access challenges. If you are a developer who likes to learn by example, then this is the right book for you.

  • Gives ready-to-use, real-world recipes to help you with everyday tasks

  • Places strong focus on DbContext and the Code First approach

  • Covers new features such as Asynch Query and Save, Codebased Configuration, Connection Resiliency, Dependency Resolution, and much more

  • What you'll learn

  • Implement basic data access design patterns using Entity Framework.

  • Seamlessly model your solutions across both code and data.

  • Provide data access to Windows 8 and Metro applications.

  • Integrate with WCF Data Services

  • Improve data access performance.

  • Simplify and reduce your code through data binding.

  • Who this book is for

    Entity Framework 6 Recipes is for anyone learning Microsoft's Entity Framework—Microsoft's primary data access platform in the .NET Framework. If you have ever struggled to learn a new technology, programming model, or way of doing something, you know how helpful simple and real-world examples can be. For the beginning developer, this book provides concrete examples for common data access tasks. For developers having experience with previous Microsoft data access platforms, this book provides a task-by-task mapping between previous approaches and the patterns used in Entity Framework.

    Table of contents

    1. Title Page
    2. Dedication
    3. Contents at a Glance
    4. Contents
    5. About the Authors
    6. About the Technical Reviewer
    7. Preface
    8. CHAPTER 1: Getting Started with Entity Framework
      1. 1-1. A Brief Tour of the Entity Framework World
      2. 1-2. Using Entity Framework
    9. CHAPTER 2: Entity Data Modeling Fundamentals
      1. 2-1. Creating a Simple Model
      2. 2-2. Creating a Model from an Existing Database
      3. 2-3. Modeling a Many-to-Many Relationship with No Payload
      4. 2-4. Modeling a Many-to-Many Relationship with a Payload
      5. 2-5. Modeling a Self-Referencing Relationship with a Code-First Approach
      6. 2-6. Splitting an Entity Among Multiple Tables
      7. 2-7. Splitting a Table Among Multiple Entities
      8. 2-8. Modeling Table per Type Inheritance
      9. 2-9. Using Conditions to Filter an ObjectSet
      10. 2-10. Modeling Table per Hierarchy Inheritance
      11. 2-11. Modeling Is-a and Has-a Relationships Between Two Entities
      12. 2-12. Creating, Modifying, and Mapping Complex Types
    10. CHAPTER 3: Querying an Entity Data Model
      1. 3-1. Querying Asynchronously
      2. 3-2. Updating with Native SQL Statements
      3. 3-3. Fetching Objects with Native SQL Statements
      4. 3-4. Querying a Model with Entity SQL
      5. 3-5. Finding a Master That Has Detail in a Master-Detail Relationship
      6. 3-6. Setting Default Values in a Query
      7. 3-7. Returning Multiple Result Sets from a Stored Procedure
      8. 3-8. Comparing Against a List of Values
      9. 3-9. Filtering Related Entities
      10. 3-10. Applying a Left-Outer Join
      11. 3-11. Ordering by Derived Types
      12. 3-12. Paging and Filtering
      13. 3-13. Grouping by Date
      14. 3-14. Flattening Query Results
      15. 3-15. Grouping by Multiple Properties
      16. 3-16. Using Bitwise Operators in a Filter
      17. 3-17. Joining on Multiple Columns
    11. CHAPTER 4: Using Entity Framework in ASP.NET MVC
      1. 4-1. Building CRUD Operations in an ASP.NET MVC Page
      2. 4-2. Building a Search Query
      3. 4-3. Filtering with ASP.NET’s URL Routing
    12. CHAPTER 5: Loading Entities and Navigation Properties
      1. 5-1. Lazy Loading Related Entities
      2. 5-2. Eager Loading Related Entities
      3. 5-3. Finding Single Entities Quickly
      4. 5-4. Querying In-Memory Entities
      5. 5-5. Loading a Complete Object Graph
      6. 5-6. Loading Navigation Properties on Derived Types
      7. 5-7. Using Include( ) with Other LINQ Query Operators
      8. 5-8. Deferred Loading of Related Entities
      9. 5-9. Filtering and Ordering Related Entities
      10. 5-10. Executing Aggregate Operations on Related Entities
      11. 5-11. Testing Whether an Entity Reference or Entity Collection Is Loaded
      12. 5-12. Loading Related Entities Explicitly
      13. 5-13. Filtering an Eagerly Loaded Entity Collection
      14. 5-14. Modifying Foreign Key Associations
    13. CHAPTER 6: Beyond the Basics with Modeling and Inheritance
      1. 6-1. Retrieving the Link Table in a Many-to-Many Association
      2. 6-2. Exposing a Link Table as an Entity
      3. 6-3. Modeling a Many-to-Many, Self-Referencing Relationship
      4. 6-4. Modeling a Self-Referencing Relationship Using Table per Hierarchy Inheritance
      5. 6-5. Modeling a Self-Referencing Relationship and Retrieving a Complete Hierarchy
      6. 6-6. Mapping Null Conditions in Derived Entities
      7. 6-7. Modeling Table per Type Inheritance Using a Nonprimary Key Column
      8. 6-8. Modeling Nested Table per Hierarchy Inheritance
      9. 6-9. Applying Conditions in Table per Type Inheritance
      10. 6-10. Creating a Filter on Multiple Criteria
      11. 6-11. Using Complex Conditions with Table per Hierarchy Inheritance
      12. 6-12. Modeling Table per Concrete Type Inheritance
      13. 6-13. Applying Conditions on a Base Entity
      14. 6-14. Creating Independent and Foreign Key Associations
      15. 6-15. Changing an Independent Association into a Foreign Key Association
    14. CHAPTER 7: Working with Object Services
      1. 7-1. Dynamically Building a Connection String
      2. 7-2. Reading a Model from a Database
      3. 7-3. Deploying a Model
      4. 7-4. Using the Pluralization Service
      5. 7-5. Retrieving Entities from the Change Tracker
      6. 7-6. Generating a Model from the Command Line
      7. 7-7. Working with Dependent Entities in an Identifying Relationship
      8. 7-8. Inserting Entities Using a Database Context
      9. 7-9. Querying and Saving Asynchronously
    15. CHAPTER 8: Plain Old CLR Objects
      1. 8-1. Using POCO
      2. 8-2. Loading Related Entities with POCO
      3. 8-3. Lazy Loading with POCO
      4. 8-4. POCO with Complex Type Properties
      5. 8-5. Notifying Entity Framework About Object Changes
      6. 8-6. Retrieving the Original (POCO) Object
      7. 8-7. Manually Synchronizing the Object Graph and the Change Tracker
      8. 8-8. Testing Domain Objects
      9. 8-9. Testing a Repository Against a Database
    16. CHAPTER 9: Using the Entity Framework in N-Tier Applications
      1. 9-1. Updating Single Disconnected Entities with the Web API
      2. 9-2. Updating Disconnected Entities with WCF
      3. 9-3. Finding Out What Has Changed with Web API
      4. 9-4. Implementing Client-Side Change Tracking with Web API
      5. 9-5. Deleting an Entity When Disconnected
      6. 9-6. Managing Concurrency When Disconnected
      7. 9-7. Serializing Proxies in a WCF Service
    17. CHAPTER 10: Stored Procedures
      1. 10-1. Returning an Entity Collection with Code Second
      2. 10-2. Returning Output Parameters
      3. 10-3. Returning a Scalar Value Result Set
      4. 10-4. Returning a Complex Type from a Stored Procedure
      5. 10-5. Defining a Custom Function in the Storage Model
      6. 10-6. Populating Entities in a Table per Type Inheritance Model
      7. 10-7. Populating Entities in a Table per Hierarchy Inheritance Model
      8. 10-8. Mapping the Insert, Update, and Delete Actions to Stored Procedures
      9. 10-9. Using Stored Procedures for the Insert and Delete Actions in a Many-to-Many Association
      10. 10-10. Mapping the Insert, Update, and Delete Actions to Stored Procedures for Table per Hierarchy Inheritance
    18. CHAPTER 11: Functions
      1. 11-1. Returning a Scalar Value from a Model-Defined Function
      2. 11-2. Filtering an Entity Collection Using a Model-Defined Function
      3. 11-3. Returning a Computed Column from a Model-Defined Function
      4. 11-4. Calling a Model-Defined Function from a Model-Defined Function
      5. 11-5. Returning an Anonymous Type from a Model-Defined Function
      6. 11-6. Returning a Complex Type from a Model-Defined Function
      7. 11-7. Returning a Collection of Entity References from a Model-Defined Function
      8. 11-8. Using Canonical Functions in eSQL
      9. 11-9. Using Canonical Functions in LINQ
      10. 11-10. Calling Database Functions in eSQL
      11. 11-11. Calling Database Functions in LINQ
      12. 11-12. Defining Built-in Functions
    19. CHAPTER 12: Customizing Entity Framework Objects
      1. 12-1. Executing Code When SaveChanges( ) Is Called
      2. 12-2. Validating Property Changes
      3. 12-3. Logging Database Connections
      4. 12-4. Recalculating a Property Value When an Entity Collection Changes
      5. 12-5. Automatically Deleting Related Entities
      6. 12-6. Deleting All Related Entities
      7. 12-7. Assigning Default Values
      8. 12-8. Retrieving the Original Value of a Property
      9. 12-9. Retrieving the Original Association for Independent Associations
      10. 12-10. Retrieving XML
      11. 12-11. Applying Server-Generated Values to Properties
      12. 12-12. Validating Entities on Saving Changes
    20. CHAPTER 13: Improving Performance
      1. 13-1. Optimizing Queries in a Table per Type Inheritance Model
      2. 13-2. Retrieving a Single Entity Using an Entity Key
      3. 13-3. Retrieving Entities for Read-Only Access
      4. 13-4. Efficiently Building a Search Query
      5. 13-5. Making Change Tracking with POCO Faster
      6. 13-6. Auto-Compiling LINQ Queries
      7. 13-7. Returning Partially Filled Entities
      8. 13-8. Moving an Expensive Property to Another Entity
      9. 13-9. Avoiding Include
      10. 13-10. Generating Proxies Explicitly
    21. CHAPTER 14: Concurrency
      1. 14-1. Applying Optimistic Concurrency
      2. 14-2. Managing Concurrency When Using Stored Procedures
      3. 14-3. Reading Uncommitted Data
      4. 14-4. Implementing the “Last Record Wins” Strategy
      5. 14-5. Getting Affected Rows from a Stored Procedure
      6. 14-6. Optimistic Concurrency with Table Per Type Inheritance
      7. 14-7. Generating a Timestamp Column with Model First
    22. Index

    Product information

    • Title: Entity Framework 6 Recipes, Second Edition
    • Author(s):
    • Release date: October 2013
    • Publisher(s): Apress
    • ISBN: 9781430257882