You are previewing Entity Framework 4.1: Expert's Cookbook.
O'Reilly logo
Entity Framework 4.1: Expert's Cookbook

Book Description

More than 40 recipes for successfully mixing Test Driven Development, architecture, and Entity Framework Code First with this book and ebook.

  • Hands-on solutions with reusable code examples

  • Strategies for enterprise ready usage

  • Examples based on real world experience

  • Detailed and advanced examples of query management

  • Step-by-step recipes that will guide you to success

In Detail

Entity Framework 4.1 allows us to dive into the world of data access without having to write SQL statements. With the power to shape data access by your object model comes questions and this book holds the answers.

Entity Framework 4.1: Expert’s Cookbook holds many examples to help guide you through tough technical decisions and avoid technical landmines. The book will guide you from just using Entity Framework to enhancing the data access wizard.

This book starts with examples that require some familiarity of object relational mappers, and then moves on to more advanced tasks. You will be guided through complex mapping scenarios, query definition, reusability, integration with other technologies, and architectural management. The approach is step-by-step and test driven so that it is focused as much as possible on solving problems and getting the most out of the time spent working through the book.

Entity Framework 4.1: Expert’s Cookbook is a must have for any .NET developer who uses Entity Framework, and wants better, cleaner, and more maintainable code.

Table of Contents

  1. Entity Framework 4.1: Expert's Cookbook
    1. Table of Contents
    2. Entity Framework 4.1: Expert's Cookbook
    3. Credits
    4. About the Authors
    5. About the Reviewers
    6. www.PacktPub.com
      1. Support files, eBooks, discount offers and more
        1. Why Subscribe?
        2. Free Access for Packt account holders
        3. Instant Updates on New Packt Books
    7. Preface
      1. What this book covers
      2. What you need for this book
      3. Who this book is for
      4. Conventions
      5. Reader feedback
      6. Customer support
        1. Downloading the example code
        2. Errata
        3. Piracy
        4. Questions
    8. 1. Improving Entity Framework in the Real World
      1. Introduction
      2. Improving Entity Framework by using code first
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. Convention over configuration
          2. Model-View-Controller
          3. Single responsibility principle
          4. Testing
        5. See also
      3. Creating mock database connections
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. One object under test
          2. Integration tests
          3. Arrange, act, assert
      4. Implementing the repository pattern
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. Dependency inversion principle
          2. Repository and caching
          3. Mocking
          4. Where constraint
        5. See also
      5. Implementing the unit of work pattern
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. Call per change
          2. Interface segregation principle
          3. Refactor
        5. See also
      6. Testing queries
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. Query execution plan
          2. Query performance
        5. See also
      7. Creating databases from code
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. Configuration and creation
          2. Sample data
      8. Testing queries for performance
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. Why do performance testing?
        5. See also
      9. Performing load testing against a database
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. Stress testing
          2. Real-world simulation
        5. See also
    9. 2. Understanding the Fluent Configuration API
      1. Introduction
      2. Improving property maps
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. Mapping storage
          2. More fluent configurations
          3. Finding tools to help
        5. See also
      3. Creating one-to-one maps
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. Using more fluent configurations
          2. Considering eager versus lazy
        5. See also
      4. Creating one-to-many maps
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. More fluent configurations
          2. More than one way to improve
        5. See also
      5. Creating many-to-many maps
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. Payload
          2. More fluent configuration
        5. See also
      6. Mapping one table to many objects
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. The cost
          2. Shared primary key association
        5. See also
      7. Mapping many tables to one object
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. When to combine tables
          2. Security concerns
        5. See also
      8. Handling inheritance based on database values
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. Table per hierarchy
          2. Table per type
          3. Table per concrete type
        5. See also
      9. Handling complex key maps
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. Keys are used for relationships
        5. See also
    10. 3. Handling Validation in Entity Framework
      1. Introduction
      2. Validating simple properties
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. Deciding between configuration and attributes
          2. Sharing validation
          3. Delaying validation
          4. Displaying error messages
        5. See also
      3. Validating complex properties
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. Reusing the base class logic
          2. Performing all at once validation
        5. See also
      4. Validating collection properties
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. Limiting reusability
          2. Validating the internal structure
        5. See also
      5. Creating custom property validation
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. Coupling
          2. Avoiding complexity
        5. See also
      6. Improving MVC UI with entity framework validation
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. Understanding the Html helper
    11. 4. Working with Transactions and Stored Procedures
      1. Introduction
      2. Using transaction scopes
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. Ensuring read/update separation
          2. Triggering – careful now
          3. Remembering that size matters
        5. See also
      3. Handling multiple context transactions
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. Atomic
          2. Consistent
          3. Isolation
          4. Durability
      4. Executing stored procedures
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. Handling return type mapping
          2. Remembering access rules
        5. See also
      5. Retrieving entities with stored procedures
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. Column Mapping
        5. See also
      6. Updating entities with stored procedures
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. Manually changing states
          2. Abstract usage
          3. Extensions for stored procedure support
        5. See also
    12. 5. Improving Entity Framework with Query Libraries
      1. Introduction
      2. Creating reusable queries
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. Extension methods
          2. Naming conflict
        5. See also
      3. Improving entity and library reuse
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. Schema and contract
          2. NuGet
      4. Implementing composed queries
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. Don't repeat yourself (DRY)
          2. Single responsibility principle
        5. See also
      5. Increasing performance with code access
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. Developer discipline
          2. Cost of architecture
        5. See also
      6. Improving query testing
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. IQueryable<T>
          2. IEnumerable
        5. See also
    13. 6. Improving Complex Query Scenarios
      1. Introduction
        1. Improving dynamic sorting
        2. Getting ready
        3. How to do it...
        4. How it works...
        5. There's more...
          1. Expression Trees
          2. Deferred execution
          3. Encapsulation
        6. See also
      2. Grouping at runtime without Lambda
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. System.Linq.Dynamic
          2. Separation of concern
          3. AsQueryable and AsEnumerable
        5. See also
      3. Handling explicit loading
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. Lambda statements
          2. LINQ aggregate
          3. Expression of function of T
      4. Improving complex where clauses
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. Compose-able LINQ
        5. See also
      5. Implementing the specification pattern
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. Specification pattern
        5. See also
    14. 7. Using Concurrent and Parallel Processing
      1. Introduction
      2. Implementing optimistic concurrency
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. Atomic execution
          2. Leaving no mess behind
          3. Isolation
        5. See also
      3. Managing parallel contexts
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. Race conditions
          2. Locking
        5. See also
      4. Handling data retrieval in highly-threaded environments
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. Client wins
          2. Store wins
          3. Custom determined
        5. See also
      5. Attaching objects with unit of work
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. Attaching related objects
          2. Detaching objects
        5. See also
      6. Improving multiple context performance
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. Thread interleaving
          2. Data race conditions
          3. Chess
    15. 8. Improving Entity Framework with Complex Business Scenarios
      1. Introduction
      2. Handling soft delete
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. Entity framework interceptors
          2. Soft delete pattern
        5. See also
      3. Implementing refreshing data on save
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. EntityState
          2. EntityKey
          3. DbEntityEntry
        5. See also
      4. Capturing the audit data
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. Created date and created by, modified date and modified by
          2. Action taken
        5. See also
      5. Improving MVC 3 applications
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. Specification pattern
          2. Expression trees
          3. Strategy pattern
        5. See also
    16. Index