Entity Framework Core in Action
Jon Smith
  • MEAP began February 2017
  • Publication in Spring 2018 (estimated)
  • ISBN 9781617294563
  • 500 pages (estimated)
  • printed in black & white

Reading and storing data is a core part of any application, and as a .NET developer you want database access to be easy and intuitive. Entity Framework Core is a .NET library designed to simplify data persistence, bridging the mismatch between the different structures of object-oriented code and relational databases. With EF Core, you can access data using abstract objects and properties without tightly coupling your code to the underlying relational database structure. And because it's part of Microsoft's open source .NET Core initiative, EF works on Windows, Linux and MacOS, and even mobile platforms via Microsoft's Xamarin.

"This book is a must have to start your journey with EF Core framework."

~ Julien Pohie

"The author is clearly a total expert."

~ Stephen Byrne

"Coherent, concise and to the point, the material is well written and it's a pleasure to read it."

~ Philip Taffet

Table of Contents detailed table of contents

Part 1: Getting started

1. Introduction to Entity Framework Core

1.1. What you will learn from this book

1.2. My "lightbulb moment" with EF

1.3. Some words for existing EF6.x developers

1.4. An overview of what EF Core is

1.4.1. The down sides of O/RMs

1.5. What about NoSQL?

1.6. My First EF Core application

1.6.1. What you will need to install

1.6.2. Creating your own .NET Core console application with EF Core

1.7. The database my MyFirstEfCoreApp application will access

1.8. Setting up the MyFirstEfCoreApp application

1.8.1. The classes that map to the database — Book and Author classes

1.8.2. The application's DbContext

1.9. Looking "under the hood" of EF Core

1.9.1. Modelling the database

1.9.2. Reading data from the database

1.9.3. Updating the database

1.10. Should I use EF Core in my next project?

1.10.1. Latest generation

1.10.2. Multi-platform and open-source

1.10.3. Rapid development

1.10.4. Well supported

1.10.6. Stable Library

1.10.7. Always high performance

1.10.8. Access to all .NET 4.6 libraries

1.11. When should you not use EF Core

1.12. Summary

2. Querying the database

2.1. Setting the scene — my book selling site example

2.1.1. Our book selling site relational database

2.1.2. Other relationship types not covered in this chapter

2.1.3. The final database showing all the tables

2.1.4. The classes that EF Core maps to the database

2.2. Creating the application's DbContext

2.2.1. Defining my application's DbContext: EfCoreContext

2.2.2. Creating an instance of my application's DbContext

2.2.3. Creating a database for your own application

2.3. Anatomy of a database query

2.3.1. Application's DbContext Property access

2.3.2. A series of LINQ/EF Core command

2.3.3. The execute command

2.4.1. Eager loading: loading relationships with the primary entity class

2.4.2. Explicit loading: loading relationships after the primary entity class

2.4.3. Select loading: loading the specific parts of primary entity class and any relationships

2.5. Client vs. Server evaluation: moving part of your query into software

2.5.1. An example of using Client vs. Server evaluation to create the display string of s book's authors

2.5.2. Understanding the limitations of Client vs. Server evaluation

2.6. Building complex queries — the book selling site

2.6.1. Building the book list query using select loading

2.6.2. Introducing the architecture of the book selling site application

2.7. Adding Sorting, Filtering, and Paging to the book selling site

2.7.1. The sorting of books by price, publication date and customer ratings

2.7.2. The filtering of books by publication year and customer ratings

2.7.3. The paging of the books in the list

2.8. Putting it all together: how to combine query objects

2.9. Summary

3. Changing the database content

3.1. Introducing EF Core's entity State

3.2. Creating new entries

3.2.1. Create a single entity on its own

3.2.2. Creating a book with its authors

3.3. The core commands for updating database entries

3.3.1. Handling updates in web application - the disconnected update

3.4. Handling relationships in updates

3.4.1. Principal and dependent relationships

3.4.2. Updating One-to-One relationships — adding a PriceOffer to a book

3.4.3. Updating One-to-Many relationships — adding a review to a book

3.4.4. Updating Many-to-Many relationships — changing a book's authors

3.4.5. Advanced feature — Updating relationships via foreign key

3.5. Deleting entities

3.5.1. Deleting a dependent-only entity — no relationships

3.5.2. Deleting a principal entity which has relationships

3.6. Summary

4. Using EF Core in business logic

4.1. Why is business logic so different to other code you write?

4.2. My business need — processing an order for books

4.2.1. The business rules that I need to implement

4.3. A design pattern to help you implement business logic

4.3.1. Five guidelines for building business logic that uses EF Core

4.4. Implementing the processing an order business logic

4.4.1. Guideline 1: The business logic has first call on how the database structure is defined

4.4.2. Guideline 2: The business logic should have no distractions

4.4.3. Guideline 3: Business logic should think it is working on in-memory data

4.4.4. Guideline 4: Isolate the database access code into a separate project

4.4.5. Guideline 5: The business logic should not call EF Core's SaveChanges directly

4.4.6. Putting it all together — calling the order processing business logic

4.4.7. Any disadvantages of this business logic pattern?

4.5. Placing an order on the book selling site application

4.6. Adding extra feature to our business logic handling

4.6.1. Validating the data that you write to the database

4.6.2. Using transactions to daisy-chain a sequence of business logic code

4.7. Summary

5. Using EF Core in ASP.NET Core web applications

5.1. Introduction to ASP.NET Core

5.2. The architecture of the example book selling site

5.3. Understanding dependency injection (DI)

5.3.1. Why you need learn about dependency injection in ASP.NET Core

5.3.2. A basic example of dependency injection in ASP.NET Core

5.3.3. The lifetime of a service created by DI

5.4. Making the application's DbContext available via DI

5.4.1. Providing information on where the database is located

5.4.2. Registering your application's DbContext with the DI provider

5.5. Calling your database access code from ASP.NET Core

5.5.1. A summary of how ASP.NET Core works and the terms it uses

5.5.2. Where does the EF Core code live in the example book selling site?

5.6. Implementing the book list query page

5.7. Implementing my database methods as a DI service

5.7.1. Registering my class as a DI service

5.7.2. Inject the ChangePubDateService into the ASP.NET action method

5.7.3. Improving registering your database access classes as services

5.8. Deploying an ASP.NET Core application with a database

5.8.1. How EF Core knows where the database is on the web server

5.8.2. Creating and migrating the database

5.9. Using EF Core's Migrate to change the database structure

5.9.1. Why do I need to call the Migrate method to change my host database?

5.9.2. Migrating the database — single web application instance running

5.9.3. Migrating the database — An alternative approach for cloud hosting

5.10. Using async/await for better scalability

5.10.1. Why async/await is useful in a web application using EF Core

5.10.2. Where should I use async/await with database accesses?

5.10.3. Changing over to using async/await versions of EF Core commands

5.11. Running parallel tasks: how to provide the DbContext

5.11.1. Other ways of obtaining a new instance of the application's DbContext

5.12. Summary

Part 2: Entity Framework in depth

6. Configuring non-relational properties

7. Configuring relationships

8. Configuring advanced features

9. Going deeper into the DbContext

Part 3: Using Entity Framework in real-world applications

10. Patterns for using EF Core

11. Handling database migrations

12. Unit Testing EF Core applications

13. EF Core performance tuning

14. Worked example of performance tuning

15. Extending EF Core


Appendix A: A brief introduction to LINQ

About the book

Entity Framework Core in Action teaches developers how to add database functionality to .NET applications with EF Core. Part 1 starts with a clear introduction to what EF Core is and how it fits into your applications. Next, you'll get hands-on quickly by building a .NET application that uses a relational database with EF Core's default configuration. By the end of part 1 you will be able to build a well-structured application that uses EF Core for database access.

The second part of the book dives deeper and shows you how to change default settings as well as teaching you many EF Core commands. You'll learn how to create a database exactly the way you want it, as well as how to link to an existing database, and how to change the way database data is exposed inside your .NET application.

The last part is all about improving your skills and making you a better developer and debugger of EF Core applications. You'll learn from real-world applications of EF Core starting with a range of known patterns and practices that you can use, extending ER Core, and how to find and fix EF Core performance issues. Software developers who have never used Entity Framework and seasoned EF6.x developers, as well as anyone who wants to know what EF Core is capable of will find this book great at deepening their knowledge and making them more productive with EF Core.

What's inside

  • Querying a database
  • Creating, updating and deleting data
  • Using EF Core in business logic
  • Building a .NET web application EF Core

About the reader

This book assumes readers are familiar with .NET development and some understanding of what relational databases are. No experience with SQL needed.

About the author

Jon Smith is a full-stack software developer and architect who focuses on Microsoft's ASP.NET web applications using Entity Framework (EF) ORM on the server-side, with various front-end JavaScript libraries. Jon is especially interested in defining patterns and building libraries that improve the speed of development of ASP.NET web/database applications.

Manning Early Access Program (MEAP) Read chapters as they are written, get the finished eBook as soon as it’s ready, and receive the pBook long before it's in bookstores.
MEAP combo $49.99 pBook + eBook
MEAP eBook $39.99 pdf + ePub + kindle

FREE domestic shipping on three or more pBooks