Brian L. Gorman
Jesup, IA, USA
Any source code or other supplementary material referenced by the author in this book is available to readers on GitHub via the books product page, located at www.apress.com/9781484260432 . For more detailed information, please visit http://www.apress.com/source-code .
ISBN 978-1-4842-6043-2 e-ISBN 978-1-4842-6044-9
https://doi.org/10.1007/978-1-4842-6044-9
Brian L. Gorman 2020
This work is subject to copyright. All rights are reserved by the Publisher, whether the whole or part of the material is concerned, specifically the rights of translation, reprinting, reuse of illustrations, recitation, broadcasting, reproduction on microfilms or in any other physical way, and transmission or information storage and retrieval, electronic adaptation, computer software, or by similar or dissimilar methodology now known or hereafter developed.
The use of general descriptive names, registered names, trademarks, service marks, etc. in this publication does not imply, even in the absence of a specific statement, that such names are exempt from the relevant protective laws and regulations and therefore free for general use.
The publisher, the authors and the editors are safe to assume that the advice and information in this book are believed to be true and accurate at the date of publication. Neither the publisher nor the authors or the editors give a warranty, expressed or implied, with respect to the material contained herein or for any errors or omissions that may have been made. The publisher remains neutral with regard to jurisdictional claims in published maps and institutional affiliations.
Distributed to the book trade worldwide by Springer Science+Business Media New York, 233 Spring Street, 6th Floor, New York, NY 10013. Phone 1-800-SPRINGER, fax (201) 348-4505, e-mail orders-ny@springer-sbm.com, or visit www.springeronline.com. Apress Media, LLC is a California LLC and the sole member (owner) is Springer Science + Business Media Finance Inc (SSBM Finance Inc). SSBM Finance Inc is a Delaware corporation.
Introduction
Entity Framework is the ORM of choice for .Net development for a majority of enterprise application development teams. Through the years, EF has gone through a number of changes, and the move into the .Net Core world has seen EF become more performant and more user-friendly.
As this book begins, well take a look at the state of things as they are, and the state of things to come. In the first couple of chapters, well even look at differences in approaches to working with EF, whether you are working with EF6 or EFCore. Well touch on the two different approaches to working with the database: database first and code first. After the first three chapters, we settle in on the code-first approach with EFCore.
The great news is that no matter what approach to the database or version of EF you are using, with just a few minor exceptions, things will generally work in a similar fashion, so all of the information in this book is relevant to anyone working with Entity Framework.
Who this book is for
Practical Entity Framework is written for anyone that is new to Entity Framework or is still learning and wants to become much better with Entity Framework.
If you are already an expert or a well-established developer with a few years of EF under your belt, this book will likely not have a lot of new information for you.
Overall, the book is designed to work through the moving pieces that are necessary to understand and work with EF, as well as how to approach architecting SOLID solutions around EF. The practical nature of each activity will give you many examples and cover a lot of the basic and advanced topics you will likely encounter in real-world applications.
How this book is structured and what is covered in the chapters
This book has been developed into four parts. Part 1 contains the first three chapters and covers many of the introductory topics and contrasts in approaches to using the database in EF. Part 2, which includes Chapters and discusses more recipes for success and a look into the future of EF.
Part 1 Getting Started
Chapter , Introduction to Entity Framework, begins by discussing the current state of enterprise applications with Entity Framework. In the chapter, we take a look at how to get set up and start building out a solution with Entity Framework.
Chapter , Working with an Existing Database, discusses the approach developers might need to take if there is already an established database and the solution needs to use EF. The chapter uses a copy of the AdventureWorks database and covers how to work with the EFCore tools to reverse engineer a database, as well as how to use the database-first approach in EF6.
Chapter , Entity Framework: Code First, starts with a discussion of what it means to be code first and when it may not make sense to use the approach, and then quickly moves into the benefits of using a code-first approach. The activities walk through implementing a code-first approach in EFCore and EF6.
Part 2 Building the Data Solution
Chapter , Models and the Data Context, covers working with our entities to build out the objects that represent the tables in the database and then execute the migrations to make sure the tables exist as defined in code. The activities in this chapter reinforce that learning.
Chapter , Constraints, Keys, and Relationships, takes a look at how to set the primary keys, multiple column keys, and database relationships that you will likely encounter. The activities cover setting up constraints, index, and relationships in EFCore.
Chapter , Data Access (Create, Read, Update, Delete), is a critical chapter to learn how to do the CRUD operations against your database. In the activity for this chapter, we spin up a website and see how quickly we can build out CRUD operations.
Chapter , Stored Procedures, Views, and Functions, continues our learning of practical applications of EF with a good luck at what it takes to incorporate database objects into the code-first solution. The activities cover setting up and working with stored procedures, functions, views, and seeding data.
Chapter , Sorting, Filtering, and Paging, takes a deeper dive into working with LINQ to get data and ensuring that our operations are as efficient as possible with EF. The activity for the chapter walks through sorting, filtering, and paging the data, as well as looking at working with a disconnected dataset.
Chapter , LINQ for Queries and Projections, introduces the valuable use of projections in our queries and also covers using AutoMapper in our solution. The activities get us started with projections and then implement AutoMapper into our solution.