Eric Vogel
Okemos, MI, 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/9781484268810 . For more detailed information, please visit http://www.apress.com/source-code .
ISBN 978-1-4842-6881-0 e-ISBN 978-1-4842-6882-7
https://doi.org/10.1007/978-1-4842-6882-7
Eric Vogel 2021
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 LLC, 1 New York Plaza, Suite 4600, New York, NY 10004. 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
This book is aimed at readers who have a beginners knowledge of the .NET Framework who are looking to use Entity Framework (EF) Core 5 for a side project or business application. No prior knowledge of Entity Framework Core 5 is required. The book guides the user through the basics of Entity Framework Core 5 up to some more advanced concepts and culminates in creating an ASP.NET Core Razor Pages web application that has full create, read, update, and delete (CRUD) capability.
We will be using the NUnit Framework to test Entity Framework Core 5 behavior before using it in a full web application. You will first go over how to query data and then how to insert, update, and delete data. Later in the book, we will go over more advanced techniques like how to aggregate data, use navigation properties to get related data, and call custom raw SQL and stored procedures.
The later chapters also cover basic authentication, authorization, and reporting in an ASP.NET Core Razor Pages web application. You will learn how to query and manipulate a SQL Server database by testing each facet through NUnit integration tests.
Eric Vogel 2021
E. Vogel Beginning Entity Framework Core 5 https://doi.org/10.1007/978-1-4842-6882-7_1
1. Installation
In order to use Entity Framework Core 5, you will need some tools. These tools include Visual Studio (VS) 2019 and some NuGet packages for your solution.
Install Visual Studio
The first step is getting a version of Visual Studio 2019. The Community Edition of Visual Studio 2019 for Windows can be used for all code in this book. If you are running macOS, you can also opt to install Visual Studio for Mac. Ill be using Windows for the remainder of the book, but the steps are about the same for macOS.
You can download Visual Studio 2019 from .
Figure 1-1
Download VS 2019
Next, install the latest Visual Studio 2019 and select the .NET Core option as seen in Figure .
Figure 1-2
Install .NET Core Support
Entity Framework Core 5 will run on both .NET Core 3.1 and .NET 5. For this book, we will be using .NET Core 3.1.
Create a Project
Entity Framework Core 5 works on a variety of application types from console apps, desktop apps, and web apps. For this book, we will be creating an ASP.NET Core MVC (Model-View-Controller) app.
We will now create the project in Visual Studio and install all the required tools to use Entity Framework Core 5. First, create a new project in Visual Studio as seen in Figure .