You are previewing Entity Framework Tutorial - Second Edition.
O'Reilly logo
Entity Framework Tutorial - Second Edition

Book Description

A comprehensive guide to the Entity Framework with insight into its latest features and optimizations for responsive data access in your projects

About This Book

  • Create Entity data models from your database and use them in your applications
  • Learn about the Entity Client data provider and write statements in Entity SQL to perform CRUD operations
  • Explore ADO.NET Data Services and how they work with the Entity Framework
  • Who This Book Is For

    If you are a C# developer who wants to learn a new way of querying data and utilizing it in applications efficiently for data binding or other operations, then this book is for you. Basic knowledge of ADO.NET is assumed.

    What You Will Learn

  • Explore the features of the ADO.NET Entity Framework
  • Understand the concepts of entities and their relationships
  • Create an Entity Data Model using the ADO.NET Entity Data Model Designer and the EdmGen tool
  • Extend existing Entity Types to create your own Entity Types
  • Write programs against the Entity Data Model to perform CRUD operations
  • Discover ADO.NET Data Services and learn how they can be used with the Entity Framework
  • Familiarize yourself with WCF Data Services (formerly ADO.NET Data Services)
  • Apply Code First, Model First and Database First approaches
  • In Detail

    The ADO.NET Entity Framework from Microsoft is a new ADO.NET development framework that provides a level of abstraction for data access strategies and solves the impedance mismatch issues that exist between different data models.

    This book explores Microsoft’s Entity Framework and explains how it can used to build enterprise level applications. It will also teach you how you can work with RESTful Services and Google’s Protocol Buffers with Entity Framework and WCF. You will explore how to use Entity Framework with ASP.NET Web API and also how to consume the data exposed by Entity Framework from client applications of varying types, i.e., ASP.NET MVC, WPF and Silverlight. You will familiarize yourself with the new features and improvements introduced in Entity Framework including enhanced POCO support, template-based code generation, tooling consolidation and connection resiliency. By the end of the book, you will be able to successfully extend the new functionalities of Entity framework into your project.

    Style and approach

    This book is a step-by-step tutorial providing hands-on code examples with detailed explanations. The book aims to explain the concepts of the Entity Framework and illustrate how you can use these in applications with a tutorial based approach.

    Downloading the example code for this book. You can download the example code files for all Packt books you have purchased from your account at http://www.PacktPub.com. If you purchased this book elsewhere, you can visit http://www.PacktPub.com/support and register to have the code file.

    Table of Contents

    1. Entity Framework Tutorial Second Edition
      1. Table of Contents
      2. Entity Framework Tutorial Second Edition
      3. Credits
      4. About the Author
      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
      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. Introducing the ADO.NET Entity Framework
        1. What you should know
        2. Looking back
        3. What is the ADO.NET Entity Framework?
          1. Is Entity Framework just another ORM?
        4. A comparative analysis of Entity Framework and other ORM tools
          1. LINQ to SQL and .dbml files
        5. Entity Framework architectural components
          1. The Entity Data Model
          2. How is the EDM represented?
          3. The Object Model (O-Space)
          4. LINQ to Entities
          5. Entity Client
          6. Entity SQL
            1. Avoiding complex joins
          7. The Object Services Layer
          8. Features and benefits at a glance
        6. System requirements
          1. Support for persistence ignorance
          2. Support for T4 code generation
          3. Support for lazy loading
          4. Support for POCO change tracking
          5. Better n-tier support with self-tracking entities
          6. Support for code-first, model-first, and database-first approaches
          7. Support for built-in functions and UDF support
          8. Support for model-defined functions
          9. Enum support
          10. Spatial data types support
          11. Other enhancements
        7. Performance improvements in Entity Framework 6
        8. New features in Entity Framework 7
        9. Summary
      9. 2. Getting Started
        1. Designing the UserAuthentication database
        2. Creating the EDM
          1. Creating the Entity Data Model using the ADO.NET Entity Data Model Designer
          2. Creating Entity Data Model using the EdmGen tool
        3. The DataSource controls
          1. The ObjectDataSource control
          2. The SqlDataSource control
          3. The SiteMapDataSource control
          4. The XMLDataSource control
          5. The LinqDataSource control
          6. The EntityDataSource control
        4. Implementing our first application using the Entity Framework
        5. Summary
      10. 3. Entities, Relationships, and the Entity Data Model
        1. Entities, entity types, and relationships in the EDM
          1. What is an entity?
          2. Defining entity sets in the EDM
          3. Extending the existing entity types to create derived entity types
          4. Association sets, associations, containment, and multiplicity
          5. What are entity containers?
        2. Exploring the Security EDM
          1. The Mapping Details window
          2. The Entity Model browser
          3. The EDM layers
            1. The CSDL schema
            2. The SSDL schema
            3. The MSL schema
          4. Entity classes
        3. Summary
      11. 4. Working with Stored Procedures in the Entity Data Model
        1. Creating a database using model-first development
        2. Creating stored procedures
        3. Mapping stored procedures to functions in the EDM
          1. Mapping the create, update, and delete functions to entities in the EDM
          2. Mapping stored procedures with no entity set
        4. Executing stored procedures using the EDM
        5. Mapping stored procedures that return custom entity types
        6. Summary
      12. 5. Working with Entity Client and Entity SQL
        1. An overview of the E-SQL language
        2. From T-SQL to E-SQL
        3. Why E-SQL when I already have LINQ to Entities?
          1. Features of E-SQL
          2. Operators in E-SQL
            1. Arithmetic operators
            2. Comparison operators
            3. Logical operators
            4. Reference operators
            5. Type operators
            6. Set operators
            7. Operator precedence
          3. Expressions in E-SQL
            1. Query expressions in E-SQL
          4. Identifiers, variables, parameters, and types in E-SQL
            1. Row
            2. Collections
            3. Reference
          5. Canonical functions in E-SQL
            1. Mathematical functions
            2. Aggregate functions
            3. String functions
            4. Bitwise functions
            5. Date and time functions
        4. Data paging using E-SQL
        5. Working with the ADO.NET Entity Client
          1. Let's get into action
            1. Building the connection string
            2. Creating an entity connection
            3. Opening the connection
            4. Executing queries using the entity command
            5. Closing the connection
        6. Other operations with E-SQL
          1. Inserting a record using E-SQL
          2. Inserting a record with a foreign key constraint
          3. Retrieving native SQL from EntityCommand
          4. Transaction management in E-SQL
        7. Deferred, eager, and lazy loading
        8. Summary
      13. 6. Working with LINQ to Entities
        1. Introducing LINQ
          1. Why LINQ?
        2. Understanding the LINQ architecture
          1. LINQ to XML
          2. LINQ to SQL
          3. LINQ to Objects
          4. LINQ to Entities
            1. Querying data using LINQ to Entities
            2. LINQ to Entities and Entity Framework
            3. Differences between LINQ to Entities and LINQ to SQL
        3. Parallel LINQ
        4. Operators in LINQ
          1. Aggregation
          2. Projections
          3. Ordering
          4. Quantifiers
          5. Restriction
          6. Conversion
          7. Element
          8. Set
        5. Querying data using LINQ
          1. Expressions in LINQ to Entities
            1. Constant expressions
            2. Comparison expressions
            3. Initialization expressions
            4. Null comparisons
            5. Navigation properties
            6. Immediate and deferred query execution
            7. Retrieving entity data from the Security database
        6. Summary
      14. 7. Working with the Object Services Layer
        1. What are Object Services?
          1. Features at a glance
          2. The SecurityDbEntity's DbContext class
          3. Querying data as in-memory objects
          4. Using Entity Framework 7
        2. Performing CRUD operations on objects
        3. Attaching and detaching objects to and from ObjectContext
        4. Serializing and deserializing entity instances
        5. Change tracking and identity resolution using ObjectContext
        6. Understanding the code-first, model-first, and database-first approaches to domain design
          1. Using the code-first approach
          2. Using the model-first approach
          3. Using the database-first approach
        7. Inheritance in Entity Framework
          1. Table-per-Hierarchy
          2. Table-per-Type
          3. Table-per-Concrete Type
        8. Implementing complex types in the EDM
        9. State management, identity management, and relationship management
        10. Reading objects from the Security database
        11. Inserting objects from the Security database
        12. Editing objects from the Security database
        13. Deleting objects from the Security database
        14. Summary
      15. 8. Working with WCF Data Services
        1. Introducing WCF Data Services
          1. How do WCF Data Services and Web Services differ?
          2. What is Representational State Transfer (REST)?
          3. Why use WCF Data Services?
            1. The features at a glance
        2. Exposing data as a service using WCF Data Services
        3. Why do we need REST?
          1. Resources in REST-based architecture
          2. The REST architectural constraints
            1. The client-server model
            2. Stateless
            3. Cacheable
            4. Code on demand
            5. The uniform interface
            6. Resource management
          3. REST attributes
            1. WebServiceHost
            2. WebHttpBinding
            3. WebHttpBehavior
            4. WebOperationContext
            5. WebMessageFormat
            6. The WebGet attribute
            7. The WebInvoke attribute
            8. UriTemplate
          4. REST-based Web Services
        4. What is the OData Protocol?
        5. Working with WCF Data Services and Entity Framework
        6. Working with OData Services using WCF and ASP.NET MVC Framework
        7. Working with Protobuf WCF Services
          1. Protocol Buffers
            1. Creating Protobuf-net objects
            2. Integrating Protobuf.NET with Visual Studio
            3. Implementing the WCF Service
            4. Specifying binding information
        8. Summary
      16. A. Advanced Concepts
        1. REST and REST-based service frameworks
          1. Ruby on Rails
          2. Restlet
          3. Django REST
          4. The Flickr REST API
          5. The Google API
          6. Yahoo Social REST APIs
          7. Exploring OData
        2. HTTP methods, request, and response codes
        3. Abbreviations
        4. New features in Entity Framework 7
        5. Suggested reading
      17. Index