O'Reilly logo

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Code-First Development with Entity Framework

Book Description

Take your data access skills to the next level with Entity Framework

In Detail

Entity Framework Code-First enables developers to read and write data in a relational database system using C# or VB.NET. It is Microsoft's answer to demand for an ORM from .NET developers.

This book will help you acquire the necessary skills to program your applications using Entity Framework. You will start with database configuration and learn how to write classes that define the database structure. You will see how LINQ can be used with Entity Framework to give you access to stored data. You will then learn how to use Entity Framework to persist information in a Relational Database Management System. You will also see how you can benefit from writing ORM-based .NET code. Finally, you will learn how Entity Framework can help you to solve database deployment problems using migrations.

What You Will Learn

  • Understand what ORM tools are and what problems they solve
  • Set up a .NET application to use Entity Framework
  • Write Entity Framework code that creates, updates, and deletes application data in a database
  • Learn how to query the data using LINQ and gain insight into how LINQ fits into Entity Framework
  • Create a database structure using the Entity Framework configuration API
  • Evolve the database structure using migrations
  • Write asynchronous code and handle concurrency
  • Work with stored procedures and functions using Entity Framework

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 files e-mailed directly to you.

Table of Contents

  1. Code-First Development with Entity Framework
    1. Table of Contents
    2. Code-First Development with Entity Framework
    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 Entity Framework
      1. What is ORM?
      2. A brief history of Entity Framework
      3. The capabilities of Entity Framework
      4. The Entity Framework architecture
      5. Self-test questions
      6. Summary
    9. 2. Your First Entity Framework Application
      1. Creating a new project that uses Entity Framework
      2. Creating a new database based on .NET classes
      3. Saving a new record to the database
      4. Querying data in a database
      5. Updating a record
      6. Deleting a row from the database
      7. Introduction to schema changes
      8. Self-test questions
      9. Summary
    10. 3. Defining the Database Structure
      1. Creating table structures
        1. Mapping .NET types to SQL types
        2. Configuring primitive properties
        3. Handling nullable properties
      2. Defining relationships
        1. The One-to-Many relationship
        2. The Many-to-Many relationship
        3. The One-to-One relationship
      3. Self-test questions
      4. Summary
    11. 4. Querying, Inserting, Updating, and Deleting Data
      1. The basics of LINQ
      2. Filtering data in queries
      3. Sorting data in queries
      4. Exploring LINQ functions
        1. Element operations
        2. Quantifiers
      5. Working with related entities
        1. Filtering based on related data
        2. Lazy and eager loading
      6. Inserting data into the database
      7. Updating data in the database
      8. Deleting data from the database
        1. Working with in-memory data
      9. Self-test questions
      10. Summary
    12. 5. Advanced Modeling and Querying Techniques
      1. Advanced modeling techniques
        1. Complex types
        2. Using an explicit table and column mappings
        3. Adding supporting columns
        4. Enumerations
        5. Using multiple tables for a single entity
      2. Advanced querying techniques
        1. Projections
        2. Aggregations and grouping
        3. Advanced query construction
        4. Paging data with windowing functions
        5. Using joins
        6. Groupings and left outer joins
        7. Set operations
      3. Self-test questions
      4. Summary
    13. 6. Working with Views, Stored Procedures, the Asynchronous API, and Concurrency
      1. Working with views
      2. Working with stored procedures
        1. Create, update, and delete entities with stored procedures
      3. The asynchronous API
      4. Handling concurrency
      5. Self-test questions
      6. Summary
    14. 7. Database Migrations and Additional Features
      1. Enabling and running migrations
      2. Using the migrations API
      3. Applying migrations
        1. Applying migrations via a script
        2. Applying migrations via migrate.exe
        3. Applying migrations via an initializer
      4. Adding migrations to an existing database
      5. Additional Entity Framework features
        1. Custom conventions
        2. Geospatial data
        3. Dependency injection and logging
        4. Startup performance
        5. Multiple contexts per database
      6. Self-test questions
      7. Summary
    15. A. Answers to Self-test Questions
      1. Chapter 1: Introducing Entity Framework
      2. Chapter 2: Your First Entity Framework Application
      3. Chapter 3: Defining the Database Structure
      4. Chapter 4: Querying, Inserting, Updating, and Deleting Data
      5. Chapter 5: Advanced Modeling and Querying Techniques
      6. Chapter 6: Working with Views, Stored Procedures, the Asynchronous API, and Concurrency
      7. Chapter 7: Database Migrations and Additional Features
    16. Index