Entity Framework Core in Action, Second Edition
Jon P Smith
  • MEAP began May 2020
  • Publication in Spring 2021 (estimated)
  • ISBN 9781617298363
  • 575 pages (estimated)
  • printed in black & white
free previous edition eBook included
An eBook copy of the previous edition of this book is included at no additional cost. It will be automatically added to your Manning Bookshelf within 24 hours of purchase.

Need a good introduction into EF Core? Get this one, it's the best I've read.

Thomas Gueth
Entity Framework Core in Action, Second Edition is an in-depth guide to reading and writing databases with EF Core. Revised from the bestselling original edition, it’s filled with over 100 diagrams, code snippets, and examples—including building and scaling your own bookselling web application. Learn from author Jon Smith’s extensive experience working with EF Core in production, as you discover time-saving patterns and best practices for security, performance tuning, unit testing, and all the book’s code is available on GitHub.

About the Technology

Entity Framework Core is an object-relational mapper (ORM) that bridges the gap between your C# code and the commands required to access relational databases. As Microsoft’s recommended data access technology, it automatically maps your classes and code to the tables and views of a database—making it radically easier to query and write to databases from a .NET application. It allows you to query and write to your database using standard LINQ commands, and it will even automatically generate the model from your database schema. Now that .NET Core 5 is Microsoft’s primary development system, it’s never been more important to master Entity Framework Core.

About the book

Entity Framework Core in Action, Second Edition is a comprehensive guide to accessing databases from .NET applications. Updated and upgraded with new content, new diagrams, and new examples, this second edition of the bestselling original begins with a clear breakdown of Entity Framework, along with the mental model behind ORM. You’ll discover time-saving patterns and best practices for security, performance tuning, and even unit testing, as well as tips and tricks developed by the author through their extensive experience working on different client applications. As you go, you’ll address common data access challenges and learn how to handle them with Entity Framework.
Table of Contents detailed table of contents

PART 1 Getting Started

1 Introduction to Entity Framework Core

1.1 What you’ll learn from this book

1.2 My “lightbulb moment” with Entity Framework

1.3 Some words for existing EF6.x developers

1.4 An overview of EF Core

1.4.1 The downsides of O/RMs

1.5 What about NoSQL?

1.6 Your first EF Core application

1.6.1 What you need to install

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

1.7 The database that MyFirstEfCoreApp will access

1.8 Setting up the MyFirstEfCoreApp application

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

1.8.2 The application’s DbContext

1.9 Looking under the hood of EF Core

1.9.1 Modeling the database

1.9.2 Reading data from the database

1.9.3 Updating the database

1.10 The stages of development of EF Core

1.11 Should you use EF Core in your next project?

1.11.1 .NET 5 is the Future, and its fast!

1.11.2 Open source and open communication

1.11.3 Multi-platform applications and development

1.11.4 Rapid development, and good features

1.11.5 Well supported

1.11.6 Always high-performance

1.12 When should you not use EF Core?

1.13 Summary

2 Querying the database

2.1 Setting the scene—our book-selling site

2.1.1 The book app’s relational database

2.1.2 Other relationship types not covered in this chapter

2.1.3 The 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 the application’s DbContext: EfCoreContext

2.2.2 Creating an instance of the application’s DbContext

2.2.3 Creating a database for your own application

2.3 Understanding database queries

2.3.1 Application’s DbContext property access

2.3.2 A series of LINQ/EF Core commands

2.3.3 The execute command

2.3.4 The two types of database queries

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 specific parts of primary entity class and any relationships

2.4.4 Lazy loading: loading relationships as required

2.5 Using client vs. server evaluation: adapting data at the last stage of a query

2.6 Building complex queries

2.6 Introducing the architecture of the book app

2.7 Building complex queries

2.8 Adding sorting, filtering, and paging

2.8.1 Sorting books by price, publication date, and customer ratings

2.8.2 Filtering books by publication year and customer ratings

2.8.3 Other filtering options—searching text for a specific string

2.8.4 Paging the books in the list

2.9 Putting it all together: combining Query Objects

2.10 Summary

3 Changing the database content

3.1 Introducing EF Core’s entity State

3.2 Creating new rows in a table

3.2.1 Creating a single entity on its own

3.2.2 Creating a book with a review

3.3 Updating database rows

3.3.1 Handling disconnected updates in a web application

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 keys

3.5 Deleting entities

3.5.1 Using a soft delete—using a global query filter to “hide” entities

3.5.2 Deleting a dependent-only entity—no relationships

3.5.3 Deleting a principal entity that has relationships

3.6 Summary

4 Using EF Core in business logic

4.1 The questions to ask and the decisions you need to take before you start coding

4.1.1 Deciding what level of complexity each business logic

4.2 Complex business logic example—processing an order for books

4.3 Using a design pattern to help implement complex business logic

4.3.1 Five guidelines for building business logic that uses EF Core

4.4 Implementing the business logic for processing an order

4.4.1 Guideline 1: Business logic has first call on defining the database structure

4.4.2 Guideline 2: Business logic should have no distractions

4.4.3 Guideline 3: Business logic should think it’s working on in-memory data

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

4.4.5 Guideline 5: Business logic shouldn’t call EF Core’s SaveChanges

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

4.4.7 Placing an order on the Book App

4.4.8 The pros and cons of the complex business logic pattern

4.5 Simple business logic example – ChangePriceOfferService

4.5.1 My design approach for simple business logic

4.5.2 Writing the ChangePriceOfferService code

4.5.3 The pros and cons of this business logic pattern?

4.6 Validation business logic example – add review to a book, with checks

4.6.1 The pros and cons of this business logic pattern

4.7 Adding extra features to your business logic handling

4.7.1 Validating the data that you write to the database

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

4.8 Summary

5 Using EF Core in ASP.NET Core web applications

5.1 Introducing ASP.NET Core

5.2 Understanding the architecture of the Book App

5.3 Understanding dependency injection

5.3.1 Why you need to learn about DI 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 the database’s location

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 Book App?

5.6 Implementing the book list query page

5.7 Implementing your database methods as a DI service

5.7.1 Registering your class as a DI service

5.7.2 Injecting 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 Knowing 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’s structure

5.9.1 Updating your production database

5.9.2 Having your application migrate your database on startup

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 you use async/await with database accesses?

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

5.11 Running parallel tasks: how to provide the DbContext

5.11.1 Obtaining an instance of your application’s DbContext to run in parallel

5.11.2 Running a background service in ASP.NET Core

5.11.3 Other ways of obtaining a new instance of the application’s DbContext

5.12 Summary

6 Tips and techniques for reading and writing with EF Core

6.1 Reading from the database

6.1.1 Exploring the relational fixup stage in a query

6.1.3 Understanding what AsNoTracking and its variant do

6.1.2 Reading in hierarchical data efficiently

6.1.4 Understanding how the Include method works

6.1.5 Applying AsNoTracking after a query has finished

6.1.6 Making loading navigational collections fail-safe

6.1.7 Using Global Query Filters in real-world situations

6.1.8 Considering LINQ commands that need special attention

6.1.9 Using AutoMapper to automate building Select queries

6.1.10 Evaluating how EF Core creates an entity class when reading data in

6.2 Writing to the database with EF Core

6.2.1 Evaluating how EF Core writes entities/relationships to the database

6.2.2 Evaluating how DbContext handles writing out entities/relationships

6.2.3 A quick way to copy data with relationships

6.2.4 A quick way to delete an entity

6.3 Summary

PART 2 Entity Framework Core in Depth

7 Configuring nonrelational properties

8 Configuring relationships

9 Handling database migrations

10 Configuring advanced features and handling concurrency conflicts

11 Going deeper into the DbContext

PART 3 Using Entity Framework Core in Real-World Applications

12 Using entity events to solve business problems

13 Domain-Driven Design and other architectural approaches

14 EF Core performance tuning

15 A worked example of performance tuning

16 Different database types and Cosmos DB

17 Unit testing EF Core applications


Appendix A: A brief introduction to LINQ

What's inside

  • Read and write databases with Entity Framework Core
  • Configure EF Core to define every table and column in your database
  • Update your schema as your app grows
  • Using EF Core with ASP.NET Core web applications
  • Write and test business logic for database access
  • Looking at different architectures to use with EF Core

About the reader

For .NET developers with beginning-to-intermediate experience using relational databases.

About the author

Jon P. Smith is an independent principal software developer and architect with a special focus on .NET Core and Azure. He mainly works on the back-end of client applications, typically using EF Core and ASP.NET Core web applications. He is a working developer with clients from the USA and UK, typically designing and writing large sections of an application.

placing your order...

Don't refresh or navigate away from the page.
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.
print book $44.99 $59.99 pBook + eBook + liveBook
includes previous edition eBook
Additional shipping charges may apply
Entity Framework Core in Action, Second Edition (print book) added to cart
continue shopping
go to cart

eBook $35.99 $47.99 3 formats + liveBook
includes previous edition eBook
Entity Framework Core in Action, Second Edition (eBook) added to cart
continue shopping
go to cart

Prices displayed in rupees will be charged in USD when you check out.
customers also reading

This book 1-hop 2-hops 3-hops

FREE domestic shipping on three or more pBooks