From 83338fd3b5708d39c129ea0446b673873affd77c Mon Sep 17 00:00:00 2001 From: David Mikhayelyan Date: Mon, 24 Oct 2016 15:40:23 -0500 Subject: [PATCH 01/22] What is EF and Who should use this tutorial sections --- content/efcore/README.md | 4 ++++ .../efcore/getting-started/getting-started.md | 16 ++++++++++++++++ 2 files changed, 20 insertions(+) create mode 100644 content/efcore/README.md create mode 100644 content/efcore/getting-started/getting-started.md diff --git a/content/efcore/README.md b/content/efcore/README.md new file mode 100644 index 0000000..978833b --- /dev/null +++ b/content/efcore/README.md @@ -0,0 +1,4 @@ +# Entity Framework Core Tutorials + +[Getting Started with Entity Framework Core](getting-started/README.md) +This tutorial covers the basics of how to get started writing your first application using Entity Framework Core. \ No newline at end of file diff --git a/content/efcore/getting-started/getting-started.md b/content/efcore/getting-started/getting-started.md new file mode 100644 index 0000000..4992aeb --- /dev/null +++ b/content/efcore/getting-started/getting-started.md @@ -0,0 +1,16 @@ +# Getting Started using Entity Framework Core +by [The Raikes School](http://cse.unl.edu/raikes-school) + +## What is Entity Framework Core? + +Entity Framework Core (EF Core) is a lightweight, extensible, and cross-platform version of Entity Framework. Entity Framework is an object-relational mapper (O/RM) that enables .NET developers to work with a database using .NET objects. This allows developers to create and manage databases without most of the data-access code that developers usually need to write.  + +As a lightweight version of the original Entity Framework, EF Core does not have all the features available in the latest version of Entity Framework (EF6.x). However, EF Core does offer a few features EF6.x does not. For more on these differences, check out [the docs](https://docs.efproject.net/en/latest/efcore-vs-ef6/features.html). If you have further questions about which version is best for your project, visit ["Which One Is Right for You?"](https://docs.efproject.net/en/latest/efcore-vs-ef6/choosing.html). + +## Who is this tutorial meant for? + +This tutorial is meant for those new or unfamiliar to EF Core, but if you already have an understanding of EF Core, consider this a refresher course. This tutorial will also help you navigate EF Core if you are familiar with previous versions of EF. For those more experienced EF Core programmers, [the docs](https://docs.efproject.net/en/latest/) may be of more use to you. The docs feature higher level EF Core concepts that this tutorial does not. + +If you know what you're looking for, feel free to browse by topic on the side. If not, welcome! Let's get started together! + +## Prerequisites for this tuorial \ No newline at end of file From a9b80325d4ff7e637456901ad6061cb9a3cdbf10 Mon Sep 17 00:00:00 2001 From: David Mikhayelyan Date: Mon, 24 Oct 2016 15:53:22 -0500 Subject: [PATCH 02/22] Completed first draft of getting-started page --- content/efcore/getting-started/getting-started.md | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/content/efcore/getting-started/getting-started.md b/content/efcore/getting-started/getting-started.md index 4992aeb..3a1dc13 100644 --- a/content/efcore/getting-started/getting-started.md +++ b/content/efcore/getting-started/getting-started.md @@ -13,4 +13,16 @@ This tutorial is meant for those new or unfamiliar to EF Core, but if you alread If you know what you're looking for, feel free to browse by topic on the side. If not, welcome! Let's get started together! -## Prerequisites for this tuorial \ No newline at end of file +## Prerequisites for this tutorial + +This tutorial assumes a knowledge of other programming concepts, including:  + +* Basic programming concepts  +* C# (see the [interactive C# tutorial](https://www.microsoft.com/net/tutorials/csharp/getting-started)) +* Relational database concepts + - SQL-type databases will be the focus of this tutorial, though other databases function with EF Core +* LINQ statements (see this [interactive tutorial](https://www.microsoft.com/net/tutorials/csharp/getting-started/linq) for an introduction to LINQ)  + +If you're a new to these topics, you can check out their tutorials. If you're only a little rusty, we'll remind you of the relevant aspects along the way. + +Now, let's get started! \ No newline at end of file From 7962d4b1d9ad03a678007d615ae423f89d047a9c Mon Sep 17 00:00:00 2001 From: David Mikhayelyan Date: Mon, 24 Oct 2016 15:57:26 -0500 Subject: [PATCH 03/22] Changed getting-started page to the README of getting-started directory --- content/efcore/getting-started/{getting-started.md => README.md} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename content/efcore/getting-started/{getting-started.md => README.md} (100%) diff --git a/content/efcore/getting-started/getting-started.md b/content/efcore/getting-started/README.md similarity index 100% rename from content/efcore/getting-started/getting-started.md rename to content/efcore/getting-started/README.md From 0655b2a3cae7d9851391f8343f4c947c32c28a8b Mon Sep 17 00:00:00 2001 From: arynhuck Date: Tue, 25 Oct 2016 20:30:28 -0500 Subject: [PATCH 04/22] Editted README to be concise The README needed to be reorganized (some content will go into the Introduction section) and a lot of chit chat needed to be cut down. The tone is less conversational and more down-to-business (but still friendly). This will close issue #1 --- content/efcore/getting-started/README.md | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/content/efcore/getting-started/README.md b/content/efcore/getting-started/README.md index 3a1dc13..515a4d4 100644 --- a/content/efcore/getting-started/README.md +++ b/content/efcore/getting-started/README.md @@ -1,28 +1,23 @@ -# Getting Started using Entity Framework Core -by [The Raikes School](http://cse.unl.edu/raikes-school) - -## What is Entity Framework Core? - -Entity Framework Core (EF Core) is a lightweight, extensible, and cross-platform version of Entity Framework. Entity Framework is an object-relational mapper (O/RM) that enables .NET developers to work with a database using .NET objects. This allows developers to create and manage databases without most of the data-access code that developers usually need to write.  - -As a lightweight version of the original Entity Framework, EF Core does not have all the features available in the latest version of Entity Framework (EF6.x). However, EF Core does offer a few features EF6.x does not. For more on these differences, check out [the docs](https://docs.efproject.net/en/latest/efcore-vs-ef6/features.html). If you have further questions about which version is best for your project, visit ["Which One Is Right for You?"](https://docs.efproject.net/en/latest/efcore-vs-ef6/choosing.html). +# Getting Started with Entity Framework Core ## Who is this tutorial meant for? -This tutorial is meant for those new or unfamiliar to EF Core, but if you already have an understanding of EF Core, consider this a refresher course. This tutorial will also help you navigate EF Core if you are familiar with previous versions of EF. For those more experienced EF Core programmers, [the docs](https://docs.efproject.net/en/latest/) may be of more use to you. The docs feature higher level EF Core concepts that this tutorial does not. +This tutorial is meant for those new to Entity Framework (EF) Core, but if you already have an understanding of EF Core, consider this a refresher course. More advanced functionality is covered in the [docs](https://docs.efproject.net/en/latest/) . If you know what you're looking for, feel free to browse by topic on the side. If not, welcome! Let's get started together! ## Prerequisites for this tutorial -This tutorial assumes a knowledge of other programming concepts, including:  +You should understand the following concepts before starting this tutorial:  -* Basic programming concepts  * C# (see the [interactive C# tutorial](https://www.microsoft.com/net/tutorials/csharp/getting-started)) * Relational database concepts - SQL-type databases will be the focus of this tutorial, though other databases function with EF Core -* LINQ statements (see this [interactive tutorial](https://www.microsoft.com/net/tutorials/csharp/getting-started/linq) for an introduction to LINQ)  +* LINQ statements (see this [interactive tutorial](https://www.microsoft.com/net/tutorials/csharp/getting-started/linq) for an introduction to LINQ) + +## Table of Contents -If you're a new to these topics, you can check out their tutorials. If you're only a little rusty, we'll remind you of the relevant aspects along the way. +The tutorial features the following topics: -Now, let's get started! \ No newline at end of file +* Introduction to Entity Framework Core +* Adding Entity Framework Core to a Project \ No newline at end of file From ee96fa57a30d90b75f4e3b1f6f1b36f9ef2a6364 Mon Sep 17 00:00:00 2001 From: arynhuck Date: Tue, 25 Oct 2016 20:37:06 -0500 Subject: [PATCH 05/22] Cut SQL comment We don't want to tie this EF Core tutorial to a certain type of database, so I've removed SQL as a requirement. This should make this README ready to :shipit: . #1 --- content/efcore/getting-started/README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/content/efcore/getting-started/README.md b/content/efcore/getting-started/README.md index 515a4d4..a550d27 100644 --- a/content/efcore/getting-started/README.md +++ b/content/efcore/getting-started/README.md @@ -12,7 +12,6 @@ You should understand the following concepts before starting this tutorial: * C# (see the [interactive C# tutorial](https://www.microsoft.com/net/tutorials/csharp/getting-started)) * Relational database concepts - - SQL-type databases will be the focus of this tutorial, though other databases function with EF Core * LINQ statements (see this [interactive tutorial](https://www.microsoft.com/net/tutorials/csharp/getting-started/linq) for an introduction to LINQ) ## Table of Contents From aeef2f9ceaa74a2b7b12897abd89653424b6afdb Mon Sep 17 00:00:00 2001 From: arynhuck Date: Tue, 25 Oct 2016 20:37:59 -0500 Subject: [PATCH 06/22] Condensed sentence Yay wordiness. Took Ryan's suggestions and made the general description more concise. --- content/efcore/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/content/efcore/README.md b/content/efcore/README.md index 978833b..79bdd5d 100644 --- a/content/efcore/README.md +++ b/content/efcore/README.md @@ -1,4 +1,4 @@ # Entity Framework Core Tutorials [Getting Started with Entity Framework Core](getting-started/README.md) -This tutorial covers the basics of how to get started writing your first application using Entity Framework Core. \ No newline at end of file +This tutorial covers the basics of using Entity Framework Core in a C# application. \ No newline at end of file From ebff60faa601bf76b164dfb1c3d9f82717794e5e Mon Sep 17 00:00:00 2001 From: arynhuck Date: Fri, 28 Oct 2016 12:20:04 -0500 Subject: [PATCH 07/22] Changed README content, added TOC The README has been updated to be more concise and to fit with the other training-tutorials. A Table of contents has been added (when the other pages are added to the project, it will have to be updated to contain links to the markdown pages). --- content/efcore/getting-started/README.md | 19 ++----------------- content/efcore/getting-started/toc.md | 2 ++ 2 files changed, 4 insertions(+), 17 deletions(-) create mode 100644 content/efcore/getting-started/toc.md diff --git a/content/efcore/getting-started/README.md b/content/efcore/getting-started/README.md index a550d27..df8c892 100644 --- a/content/efcore/getting-started/README.md +++ b/content/efcore/getting-started/README.md @@ -1,22 +1,7 @@ # Getting Started with Entity Framework Core -## Who is this tutorial meant for? +## Who Should Read This? This tutorial is meant for those new to Entity Framework (EF) Core, but if you already have an understanding of EF Core, consider this a refresher course. More advanced functionality is covered in the [docs](https://docs.efproject.net/en/latest/) . -If you know what you're looking for, feel free to browse by topic on the side. If not, welcome! Let's get started together! - -## Prerequisites for this tutorial - -You should understand the following concepts before starting this tutorial:  - -* C# (see the [interactive C# tutorial](https://www.microsoft.com/net/tutorials/csharp/getting-started)) -* Relational database concepts -* LINQ statements (see this [interactive tutorial](https://www.microsoft.com/net/tutorials/csharp/getting-started/linq) for an introduction to LINQ) - -## Table of Contents - -The tutorial features the following topics: - -* Introduction to Entity Framework Core -* Adding Entity Framework Core to a Project \ No newline at end of file +Before beginning this tutorial, you should understand a few topics. One, this tutorial assumes a familiarity with C#. If you're new to C#, you may wish to go through the [Getting Started with C#](https://www.microsoft.com/net/tutorials/csharp/getting-started) tutorial. Two, you should have a basic knowledge of relational database concepts. Three, this tutorial will use LINQ statements. If you have not used LINQ before, the [Introducing LINQ](https://www.microsoft.com/net/tutorials/csharp/getting-started/linq) for an introduction to LINQ) tutorial can help you get up-to-speed on LINQ. diff --git a/content/efcore/getting-started/toc.md b/content/efcore/getting-started/toc.md new file mode 100644 index 0000000..86ef74b --- /dev/null +++ b/content/efcore/getting-started/toc.md @@ -0,0 +1,2 @@ +- Introduction to Entity Framework Core +- Adding Entity Framework Core to a Project \ No newline at end of file From f5d1f89d362c9fd08a5afd2cdccd3348070bae68 Mon Sep 17 00:00:00 2001 From: Rebecca Dahlman Date: Mon, 31 Oct 2016 15:44:22 -0500 Subject: [PATCH 08/22] added table of contents section, combined paragraphs, fixed wordingof LINQ section and where we mention more advanced functionality --- content/efcore/getting-started/README.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/content/efcore/getting-started/README.md b/content/efcore/getting-started/README.md index df8c892..5ef9091 100644 --- a/content/efcore/getting-started/README.md +++ b/content/efcore/getting-started/README.md @@ -2,6 +2,8 @@ ## Who Should Read This? -This tutorial is meant for those new to Entity Framework (EF) Core, but if you already have an understanding of EF Core, consider this a refresher course. More advanced functionality is covered in the [docs](https://docs.efproject.net/en/latest/) . +This tutorial is meant for those new to Entity Framework (EF) Core, as it covers the basic functionalities of EF Core. More advanced functionality is covered in the [docs](https://docs.efproject.net/en/latest/) . Before beginning this tutorial, you should understand a few topics. One, this tutorial assumes a familiarity with C#. If you're new to C#, you may wish to go through the [Getting Started with C#](https://www.microsoft.com/net/tutorials/csharp/getting-started) tutorial. Two, you should have a basic knowledge of relational database concepts. Three, this tutorial will use LINQ. If you have not used LINQ before, the [Introducing LINQ](https://www.microsoft.com/net/tutorials/csharp/getting-started/linq) tutorial can help you get up-to-speed on LINQ. -Before beginning this tutorial, you should understand a few topics. One, this tutorial assumes a familiarity with C#. If you're new to C#, you may wish to go through the [Getting Started with C#](https://www.microsoft.com/net/tutorials/csharp/getting-started) tutorial. Two, you should have a basic knowledge of relational database concepts. Three, this tutorial will use LINQ statements. If you have not used LINQ before, the [Introducing LINQ](https://www.microsoft.com/net/tutorials/csharp/getting-started/linq) for an introduction to LINQ) tutorial can help you get up-to-speed on LINQ. +## Topics Covered + +This tutorial will cover the following topics: \ No newline at end of file From 99bbf2ea6fe3bbe45aa981a724d67c7e3c1c2038 Mon Sep 17 00:00:00 2001 From: arynhuck Date: Mon, 31 Oct 2016 17:57:11 -0500 Subject: [PATCH 09/22] TOC added to README Apparently Ryan wanted this. --- content/efcore/getting-started/README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/content/efcore/getting-started/README.md b/content/efcore/getting-started/README.md index 5ef9091..8aabbf1 100644 --- a/content/efcore/getting-started/README.md +++ b/content/efcore/getting-started/README.md @@ -6,4 +6,6 @@ This tutorial is meant for those new to Entity Framework (EF) Core, as it covers ## Topics Covered -This tutorial will cover the following topics: \ No newline at end of file +This tutorial will cover the following topics: +- Introduction to Entity Framework Core +- Adding Entity Framework Core to a Project \ No newline at end of file From 916fc34ab1cfceed9b0a1d0d81606b534ac6b2d6 Mon Sep 17 00:00:00 2001 From: arynhuck Date: Mon, 31 Oct 2016 18:07:52 -0500 Subject: [PATCH 10/22] Changing how the list of prereqs looks We went with 1) 2) 3) --- content/efcore/getting-started/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/content/efcore/getting-started/README.md b/content/efcore/getting-started/README.md index 8aabbf1..6ad68b2 100644 --- a/content/efcore/getting-started/README.md +++ b/content/efcore/getting-started/README.md @@ -2,7 +2,7 @@ ## Who Should Read This? -This tutorial is meant for those new to Entity Framework (EF) Core, as it covers the basic functionalities of EF Core. More advanced functionality is covered in the [docs](https://docs.efproject.net/en/latest/) . Before beginning this tutorial, you should understand a few topics. One, this tutorial assumes a familiarity with C#. If you're new to C#, you may wish to go through the [Getting Started with C#](https://www.microsoft.com/net/tutorials/csharp/getting-started) tutorial. Two, you should have a basic knowledge of relational database concepts. Three, this tutorial will use LINQ. If you have not used LINQ before, the [Introducing LINQ](https://www.microsoft.com/net/tutorials/csharp/getting-started/linq) tutorial can help you get up-to-speed on LINQ. +This tutorial is meant for those new to Entity Framework (EF) Core, as it covers the basic functionalities of EF Core. More advanced functionality is covered in the [docs](https://docs.efproject.net/en/latest/) . Before beginning this tutorial, you should understand a few topics. 1) this tutorial assumes a familiarity with C#. If you're new to C#, you may wish to go through the [Getting Started with C#](https://www.microsoft.com/net/tutorials/csharp/getting-started) tutorial. 2) you should have a basic knowledge of relational database concepts. 3) this tutorial will use LINQ. If you have not used LINQ before, the [Introducing LINQ](https://www.microsoft.com/net/tutorials/csharp/getting-started/linq) tutorial can help you get up-to-speed on LINQ. ## Topics Covered From 59dc6d7512fc9ff868854e7eb1b238df09f0b34f Mon Sep 17 00:00:00 2001 From: arynhuck Date: Tue, 1 Nov 2016 15:46:13 -0500 Subject: [PATCH 11/22] Conciseness changes to README, emptying TOC We shortened the titles of articles, changed back to bullet points (the markdown supports it, we will just have to change what we give the website), and changed wordage. Emptied the TOC so nothing will freak out when it tries to parse documents that haven't been added yet. --- content/efcore/getting-started/README.md | 12 +++++++++--- content/efcore/getting-started/toc.md | 2 -- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/content/efcore/getting-started/README.md b/content/efcore/getting-started/README.md index 6ad68b2..70893de 100644 --- a/content/efcore/getting-started/README.md +++ b/content/efcore/getting-started/README.md @@ -2,10 +2,16 @@ ## Who Should Read This? -This tutorial is meant for those new to Entity Framework (EF) Core, as it covers the basic functionalities of EF Core. More advanced functionality is covered in the [docs](https://docs.efproject.net/en/latest/) . Before beginning this tutorial, you should understand a few topics. 1) this tutorial assumes a familiarity with C#. If you're new to C#, you may wish to go through the [Getting Started with C#](https://www.microsoft.com/net/tutorials/csharp/getting-started) tutorial. 2) you should have a basic knowledge of relational database concepts. 3) this tutorial will use LINQ. If you have not used LINQ before, the [Introducing LINQ](https://www.microsoft.com/net/tutorials/csharp/getting-started/linq) tutorial can help you get up-to-speed on LINQ. +This tutorial is aimed at people who are learning EF Core for the first time. More advanced functionality is covered in the [docs](https://docs.efproject.net/en/latest/). Before beginning this tutorial, you should understand the following topics: + +- C# (see [Getting Started with C#](https://www.microsoft.com/net/tutorials/csharp/getting-started)) +- Relational database concepts +- LINQ (see [Introducing LINQ](https://www.microsoft.com/net/tutorials/csharp/getting-started/linq)) + ## Topics Covered This tutorial will cover the following topics: -- Introduction to Entity Framework Core -- Adding Entity Framework Core to a Project \ No newline at end of file +- Intro to EF Core +- Adding EF Core to a Project +- Querying Data \ No newline at end of file diff --git a/content/efcore/getting-started/toc.md b/content/efcore/getting-started/toc.md index 86ef74b..e69de29 100644 --- a/content/efcore/getting-started/toc.md +++ b/content/efcore/getting-started/toc.md @@ -1,2 +0,0 @@ -- Introduction to Entity Framework Core -- Adding Entity Framework Core to a Project \ No newline at end of file From 2fc72647fa9bff29a4b5fc2f6dc71799ec598b55 Mon Sep 17 00:00:00 2001 From: arynhuck Date: Thu, 27 Oct 2016 15:44:52 -0500 Subject: [PATCH 12/22] Resolves #16 - Adds Intro to EF Core chapter --- content/efcore/getting-started/README.md | 4 +--- content/efcore/getting-started/intro-to-ef-core.md | 5 +++++ content/efcore/getting-started/toc.md | 1 + 3 files changed, 7 insertions(+), 3 deletions(-) create mode 100644 content/efcore/getting-started/intro-to-ef-core.md diff --git a/content/efcore/getting-started/README.md b/content/efcore/getting-started/README.md index 70893de..b4ed002 100644 --- a/content/efcore/getting-started/README.md +++ b/content/efcore/getting-started/README.md @@ -12,6 +12,4 @@ This tutorial is aimed at people who are learning EF Core for the first time. Mo ## Topics Covered This tutorial will cover the following topics: -- Intro to EF Core -- Adding EF Core to a Project -- Querying Data \ No newline at end of file +- [Intro to EF Core](what-is-ef-core.md) \ No newline at end of file diff --git a/content/efcore/getting-started/intro-to-ef-core.md b/content/efcore/getting-started/intro-to-ef-core.md new file mode 100644 index 0000000..6636216 --- /dev/null +++ b/content/efcore/getting-started/intro-to-ef-core.md @@ -0,0 +1,5 @@ +# Intro to EF Core + +Entity Framework Core (EF Core) is a lightweight, extensible, and cross-platform version of Entity Framework. Entity Framework is an object-relational mapper (O/RM) that enables .NET developers to work with a database using .NET objects. This allows developers to create and manage databases without most of the data-access code that developers usually need to write.  + +EF Core and the latest version of Entity Framework (EF6.x) differ in the features they support. A comparison of the features supported by each can be found on the [feature comparison page](https://docs.efproject.net/en/latest/efcore-vs-ef6/features.html) of the docs. If you want help determining which version is best for your project, check out the ["Which One Is Right for You?"](https://docs.efproject.net/en/latest/efcore-vs-ef6/choosing.html) page. \ No newline at end of file diff --git a/content/efcore/getting-started/toc.md b/content/efcore/getting-started/toc.md index e69de29..1041165 100644 --- a/content/efcore/getting-started/toc.md +++ b/content/efcore/getting-started/toc.md @@ -0,0 +1 @@ +- [Intro to EF Core](what-is-ef-core.md) \ No newline at end of file From 2b8e761e19837feacf89568d5ebd37753984daa8 Mon Sep 17 00:00:00 2001 From: arynhuck Date: Thu, 3 Nov 2016 16:33:47 -0500 Subject: [PATCH 13/22] 23 Installing EF Core to a computer (#24) Resolves #23 - Installing EF Core Also fixes broken link to Intro to EF Core page in the TOC and README. --- content/efcore/getting-started/README.md | 3 +- .../getting-started/installing-ef-core.md | 56 +++++++++++++++++++ content/efcore/getting-started/toc.md | 3 +- 3 files changed, 60 insertions(+), 2 deletions(-) create mode 100644 content/efcore/getting-started/installing-ef-core.md diff --git a/content/efcore/getting-started/README.md b/content/efcore/getting-started/README.md index b4ed002..9b1953d 100644 --- a/content/efcore/getting-started/README.md +++ b/content/efcore/getting-started/README.md @@ -12,4 +12,5 @@ This tutorial is aimed at people who are learning EF Core for the first time. Mo ## Topics Covered This tutorial will cover the following topics: -- [Intro to EF Core](what-is-ef-core.md) \ No newline at end of file +- [Intro to EF Core](intro-to-ef-core.md) +- [Installing EF Core](installing-ef-core.md) \ No newline at end of file diff --git a/content/efcore/getting-started/installing-ef-core.md b/content/efcore/getting-started/installing-ef-core.md new file mode 100644 index 0000000..5655e36 --- /dev/null +++ b/content/efcore/getting-started/installing-ef-core.md @@ -0,0 +1,56 @@ +# Installing EF Core + +In this lesson, you will learn how to install EF Core on your machine. You do not need to complete these steps to continue with the rest of the tutorial as the code examples in the other lessons are executable in-browser. + +## Install .NET Core + +If you haven't already, you will first need to install .NET Core on your machine. Go to the [.NET Core Page](https://www.microsoft.com/net/core) of the Microsoft website, and follow the installation instructions for your platform of choice. You can ensure .NET Core is installed by running the following command: + +``` +dotnet --version +``` + +## Create New Project + +Create a new project by running the following commands (you can skip these steps if you want to add EF Core to an existing project): + +``` +mkdir MyEfCoreProject # Create directory for project +cd MyEfCoreProject # Navigate to project directory +dotnet new # Initialize .NET Core project (generates Startup.cs and project.json) +``` + +## Add EF Core to Project + +To add EF Core to your project, you need to list it as a dependency in your `project.json` file. You need to add the appropriate package for your database provider as well. See [Database Providers](https://docs.efproject.net/en/latest/providers/index.html) in the docs for a full listing of available database providers. In this example, we use Sqlite. + +```json +"dependencies": + "Microsoft.EntityFrameworkCore.Sqlite": "1.0.0", + "Microsoft.EntityFrameworkCore.Design": { + "version": "1.0.0-preview2-final", + "type": "build" + } +} +``` + +To add EF Core functionality to the [.NET Core Command-Line Interface](https://docs.microsoft.com/en-us/dotnet/articles/core/tools/), you need to add a package to the `tools` section of `project.json`: + +``` +"tools": { + "Microsoft.EntityFrameworkCore.Tools": "1.0.0-preview2-final" +} +``` + +Once you have updated `package.json`, run the following command to install your project's tools and dependencies: + +``` +dotnet restore +``` + +After running this command, EF Core should be installed on your machine. You can run the following command to ensure EF Core was installed correctly: + +``` +dotnet ef --help +``` + diff --git a/content/efcore/getting-started/toc.md b/content/efcore/getting-started/toc.md index 1041165..f75ec13 100644 --- a/content/efcore/getting-started/toc.md +++ b/content/efcore/getting-started/toc.md @@ -1 +1,2 @@ -- [Intro to EF Core](what-is-ef-core.md) \ No newline at end of file +- [Intro to EF Core](intro-to-ef-core.md) +- [Installing EF Core](installing-ef-core.md) \ No newline at end of file From 1851ab938f22d42eba0b26c3094037e7ab256c83 Mon Sep 17 00:00:00 2001 From: arynhuck Date: Tue, 8 Nov 2016 16:26:25 -0600 Subject: [PATCH 14/22] Resolves #22 - Supported Database Providers Discusses supported database providers on the Intro to EF Core page. --- content/efcore/getting-started/intro-to-ef-core.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/content/efcore/getting-started/intro-to-ef-core.md b/content/efcore/getting-started/intro-to-ef-core.md index 6636216..d52f84c 100644 --- a/content/efcore/getting-started/intro-to-ef-core.md +++ b/content/efcore/getting-started/intro-to-ef-core.md @@ -2,4 +2,8 @@ Entity Framework Core (EF Core) is a lightweight, extensible, and cross-platform version of Entity Framework. Entity Framework is an object-relational mapper (O/RM) that enables .NET developers to work with a database using .NET objects. This allows developers to create and manage databases without most of the data-access code that developers usually need to write.  -EF Core and the latest version of Entity Framework (EF6.x) differ in the features they support. A comparison of the features supported by each can be found on the [feature comparison page](https://docs.efproject.net/en/latest/efcore-vs-ef6/features.html) of the docs. If you want help determining which version is best for your project, check out the ["Which One Is Right for You?"](https://docs.efproject.net/en/latest/efcore-vs-ef6/choosing.html) page. \ No newline at end of file +EF Core and the latest version of Entity Framework (EF6.x) differ in the features they support. A comparison of the features supported by each can be found on the [feature comparison page](https://docs.efproject.net/en/latest/efcore-vs-ef6/features.html) of the docs. If you want help determining which version is best for your project, check out the ["Which One Is Right for You?"](https://docs.efproject.net/en/latest/efcore-vs-ef6/choosing.html) page. + +## Database Providers + +At the moment, EF Core only supports relational databases, but there are plans to add support for non-relational databases in the future. Supported database providers are listed on the [Database Providers page](https://docs.efproject.net/en/latest/providers/index.html) in the docs. \ No newline at end of file From 67473897f590740b411932e6ac49bc7683f49573 Mon Sep 17 00:00:00 2001 From: Rebecca Dahlman Date: Tue, 8 Nov 2016 20:02:12 -0600 Subject: [PATCH 15/22] Resolves #3 - Querying Data Lesson --- content/efcore/getting-started/README.md | 4 +- content/efcore/getting-started/querying.md | 89 +++++++++++++++++++ .../samples/filtering-entities/Program.cs | 21 +++++ .../samples/filtering-entities/README.md | 9 ++ .../samples/loading-all-entities/Program.cs | 18 ++++ .../samples/loading-all-entities/README.md | 9 ++ .../samples/loading-single-entity/Program.cs | 16 ++++ .../samples/loading-single-entity/README.md | 9 ++ .../getting-started/samples/shared/Author.cs | 6 ++ .../getting-started/samples/shared/Book.cs | 9 ++ .../samples/shared/LibraryContext.cs | 13 +++ content/efcore/getting-started/toc.md | 3 +- 12 files changed, 204 insertions(+), 2 deletions(-) create mode 100644 content/efcore/getting-started/querying.md create mode 100644 content/efcore/getting-started/samples/filtering-entities/Program.cs create mode 100644 content/efcore/getting-started/samples/filtering-entities/README.md create mode 100644 content/efcore/getting-started/samples/loading-all-entities/Program.cs create mode 100644 content/efcore/getting-started/samples/loading-all-entities/README.md create mode 100644 content/efcore/getting-started/samples/loading-single-entity/Program.cs create mode 100644 content/efcore/getting-started/samples/loading-single-entity/README.md create mode 100644 content/efcore/getting-started/samples/shared/Author.cs create mode 100644 content/efcore/getting-started/samples/shared/Book.cs create mode 100644 content/efcore/getting-started/samples/shared/LibraryContext.cs diff --git a/content/efcore/getting-started/README.md b/content/efcore/getting-started/README.md index 9b1953d..5d928e7 100644 --- a/content/efcore/getting-started/README.md +++ b/content/efcore/getting-started/README.md @@ -12,5 +12,7 @@ This tutorial is aimed at people who are learning EF Core for the first time. Mo ## Topics Covered This tutorial will cover the following topics: + - [Intro to EF Core](intro-to-ef-core.md) -- [Installing EF Core](installing-ef-core.md) \ No newline at end of file +- [Installing EF Core](installing-ef-core.md) +- [Querying Data](querying.md) diff --git a/content/efcore/getting-started/querying.md b/content/efcore/getting-started/querying.md new file mode 100644 index 0000000..eee5cdf --- /dev/null +++ b/content/efcore/getting-started/querying.md @@ -0,0 +1,89 @@ +# Querying Data + +In this lesson, you'll learn how to use querying to fetch one or more items from your database. EF Core uses LINQ to query data, so it is important that you understand LINQ before going through this lesson. Check out the [LINQ lesson](../../csharp/getting-started/linq.md) in the C# Interactive Tutorial if you need a refresher. + +## Example database + +For this lesson, we will use a small database to allow you to try querying on your own. The database has two tables, Books and Authors, and the data is as follows: + +### Books +| BookId | AuthorId | Title | Genre | PublicationYear | +|--------|----------|---------------------------------|------------------|-----------------| +| 1 | 9 | Mrs. Dalloway | Literary | 1925 | +| 2 | 6 | The Mysterious Island | Science Fiction | 1874 | +| 3 | 7 | The Blazing World | Science Fiction | 1666 | +| 4 | 1 | The Scarlet Plague | Science Fiction | 1912 | +| 5 | 8 | The Secret Adversary | Mystery | 1922 | +| 6 | 6 | An Antarctic Mystery | Mystery | 1897 | +| 7 | 5 | My Bondage and My Freedom | Narrative | 1855 | +| 8 | 3 | The Count of Monte Cristo | Adventure | 1845 | +| 9 | 10 | Minnie's Sacrifice | Historical | 1869 | +| 10 | 4 | My Antonia | Historical | 1918 | +| 11 | 4 | O Pioneers! | Historical | 1913 | +| 12 | 2 | Adventures of Huckleberry Finn | Satire | 1884 | +| 13 | 2 | The Adventures of Tom Sawyer | Satire | 1876 | +| 14 | 10 | Iola Leroy | Historical | 1892 | +| 15 | 8 | Murder on the Orient Express | Mystery | 1934 | +| 16 | 1 | The Call of the Wild | Adventure | 1903 | +| 17 | 4 | Death Comes for the Archbishop | Historical | 1927 | + +### Authors +| AuthorId | FirstName | LastName | +|----------|------------|-----------| +| 1 | Jack | London | +| 2 | Mark | Twain | +| 3 | Alexandre | Dumas | +| 4 | Willa | Cather | +| 5 | Frederick | Douglass | +| 6 | Jules | Vern | +| 7 | Margaret | Cavendish | +| 8 | Agatha | Christie | +| 9 | Virginia | Woolf | +| 10 | Frances | Harper | +| 11 | Stephen | Crane | + +## Loading All Entities + +Let's say we want to get all of the books from our database in a C# application. Normally, we would have to write a database query in a domain-specific language, such as SQL, and then we would have to manually map the results of this query to C# objects. With EF Core, this process is much easier because it takes care of the data access code for us. + +```c# +using (var context = new LibraryContext()) +{ + var books = context.Books.ToList(); +} +``` + +In order to interact with the database via EF Core, we must first create an instance of our context (`LibraryContext`). Notice that we create the context with the `using` keyword. This automatically disposes the context after the using block has finished executing. Alternatively, we could manually call `LibraryContext.dispose()`, but the `using` method is more convenient and readable. It is imperative that we dispose of the context after we are finished using it because it holds an open connection to the database. + +Once we have an instance of the context, we can use it to interact with the database. To access the books in the database, we reference the relevant `DbSet` within the context - `Books` in our case - and call the `ToList` method to convert the `DbSet` to a `List`. The resulting list will contain all of the books within the database. + +## Filtering Entities + +Loading all of the entities from a database is useful, but there are many use cases where we only want to load a subset of the entities from the database. For example, we may want to filter books by author or genre. EF Core allows us to filter entities via the `Where` extension method. Let's look at an example where we retrieve all science fiction books from the database. + +```c# +using (var context = new LibraryContext()) +{ + var books = context.Books + .Where(b => b.Genre == "Science Fiction") + .ToList(); +} +``` + +We use a lambda expression within the `Where` method to detect if the `Genre` property of each book is equal to "Science Fiction". Books that meet the criteria of the lambda expression will be included in the final result, while books that do not will be excluded. + +We could retrieve all of the books like in the previous example and then filter them in our application; however, this would require us to load all of the books into memory, and it does not allow us to take advantage of our database's optimized querying functionality. Allowing the database to do what it does best and perform the filtering for us results in a significant performance increase. Thus, it is important that we filter the `DbSet` with the `Where` method before calling `ToList`. + +## Loading a Single Entity + +Both of our examples so far have shown how to retrieve a collection of entities. Let's look at how to retrieve a single entity based on a unique identifier. + +```c# +using (var context = new LibraryContext()) +{ + var book = context.Books + .Single(b => b.Id == 1); +} +``` + +In this example, we use the `Single` extension method to find the book with an `Id` of 1. Note that we do not need to call `ToList()` because `Single` returns a single entity. It is important to only use `Single` with unique identifiers because if multiple entities meet the success criteria a `System.InvalidOperationException` will be thrown. \ No newline at end of file diff --git a/content/efcore/getting-started/samples/filtering-entities/Program.cs b/content/efcore/getting-started/samples/filtering-entities/Program.cs new file mode 100644 index 0000000..1750d01 --- /dev/null +++ b/content/efcore/getting-started/samples/filtering-entities/Program.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; + +public class Program +{ + public static void Main() + { + using (var context = new LibraryContext()) + { + var books = context.Books + .Where(s => s.Genre.Contains("Science Fiction")) + .ToList(); + + foreach (Book book in books) + { + Console.WriteLine(String.Format("{0} - {1}", book.Title, book.Genre)); + } + } + } +} \ No newline at end of file diff --git a/content/efcore/getting-started/samples/filtering-entities/README.md b/content/efcore/getting-started/samples/filtering-entities/README.md new file mode 100644 index 0000000..2cefbae --- /dev/null +++ b/content/efcore/getting-started/samples/filtering-entities/README.md @@ -0,0 +1,9 @@ +# Filtering Entities + +This code example demonstrates how to use EF Core to query a subset of entities from the database based on specified filters. + +## Code Files: +- [Program.cs](Program.cs) +- [LibraryContext.cs](../shared/LibraryContext.cs) +- [Book.cs](../shared/Book.cs) +- [Author.cs](../shared/Author.cs) \ No newline at end of file diff --git a/content/efcore/getting-started/samples/loading-all-entities/Program.cs b/content/efcore/getting-started/samples/loading-all-entities/Program.cs new file mode 100644 index 0000000..3106389 --- /dev/null +++ b/content/efcore/getting-started/samples/loading-all-entities/Program.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.Linq; + +public class Program +{ + public static void Main() + { + using (var context = new LibraryContext()) + { + var books = context.Books.ToList(); + foreach (Book book in books) + { + Console.WriteLine(book.Title); + } + } + } +} \ No newline at end of file diff --git a/content/efcore/getting-started/samples/loading-all-entities/README.md b/content/efcore/getting-started/samples/loading-all-entities/README.md new file mode 100644 index 0000000..35b8f2b --- /dev/null +++ b/content/efcore/getting-started/samples/loading-all-entities/README.md @@ -0,0 +1,9 @@ +# Loading All Entities + +This code example demonstrates how to use EF Core to query all entities from the database. + +## Code Files: +- [Program.cs](Program.cs) +- [LibraryContext.cs](../shared/LibraryContext.cs) +- [Book.cs](../shared/Book.cs) +- [Author.cs](../shared/Author.cs) \ No newline at end of file diff --git a/content/efcore/getting-started/samples/loading-single-entity/Program.cs b/content/efcore/getting-started/samples/loading-single-entity/Program.cs new file mode 100644 index 0000000..87f69cc --- /dev/null +++ b/content/efcore/getting-started/samples/loading-single-entity/Program.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; + +public class Program +{ + public static void Main() + { + using (var context = new LibraryContext()) + { + var book = context.Books + .Single(s => s.BookId == 1); + Console.WriteLine(book.Title); + } + } +} \ No newline at end of file diff --git a/content/efcore/getting-started/samples/loading-single-entity/README.md b/content/efcore/getting-started/samples/loading-single-entity/README.md new file mode 100644 index 0000000..59c4aa7 --- /dev/null +++ b/content/efcore/getting-started/samples/loading-single-entity/README.md @@ -0,0 +1,9 @@ +# Loading A Single Entity + +This code example demonstrates how to use EF Core to query a single entity from the database. + +## Code Files: +- [Program.cs](Program.cs) +- [LibraryContext.cs](../shared/LibraryContext.cs) +- [Book.cs](../shared/Book.cs) +- [Author.cs](../shared/Author.cs) \ No newline at end of file diff --git a/content/efcore/getting-started/samples/shared/Author.cs b/content/efcore/getting-started/samples/shared/Author.cs new file mode 100644 index 0000000..8bd1c6a --- /dev/null +++ b/content/efcore/getting-started/samples/shared/Author.cs @@ -0,0 +1,6 @@ +public class Author +{ + public int AuthorId { get; set; } + public string FirstName { get; set; } + public string LastName { get; set; } +} \ No newline at end of file diff --git a/content/efcore/getting-started/samples/shared/Book.cs b/content/efcore/getting-started/samples/shared/Book.cs new file mode 100644 index 0000000..01e5070 --- /dev/null +++ b/content/efcore/getting-started/samples/shared/Book.cs @@ -0,0 +1,9 @@ +public class Book +{ + public int BookId { get; set; } + public string Title { get; set; } + public string Genre { get; set; } + public int PublicationYear { get; set; } + + public Author Author { get; set; } +} \ No newline at end of file diff --git a/content/efcore/getting-started/samples/shared/LibraryContext.cs b/content/efcore/getting-started/samples/shared/LibraryContext.cs new file mode 100644 index 0000000..236a464 --- /dev/null +++ b/content/efcore/getting-started/samples/shared/LibraryContext.cs @@ -0,0 +1,13 @@ +using Microsoft.EntityFrameworkCore; +using System.Collections.Generic; + +public class LibraryContext : DbContext +{ + public DbSet Books { get; set; } + public DbSet Authors { get; set; } + + protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) + { + optionsBuilder.UseSqlite("Filename=Library.db"); + } +} \ No newline at end of file diff --git a/content/efcore/getting-started/toc.md b/content/efcore/getting-started/toc.md index f75ec13..117193c 100644 --- a/content/efcore/getting-started/toc.md +++ b/content/efcore/getting-started/toc.md @@ -1,2 +1,3 @@ - [Intro to EF Core](intro-to-ef-core.md) -- [Installing EF Core](installing-ef-core.md) \ No newline at end of file +- [Installing EF Core](installing-ef-core.md) +- [Querying Data](querying.md) \ No newline at end of file From 2ddb531fac56e18d7f0082620cf7d8496806239b Mon Sep 17 00:00:00 2001 From: arynhuck Date: Tue, 22 Nov 2016 17:18:04 -0600 Subject: [PATCH 16/22] Resolves #27 - fixes broken links Updated links from doc.efproject.net to docs.microsoft.com --- content/efcore/getting-started/README.md | 2 +- content/efcore/getting-started/installing-ef-core.md | 2 +- content/efcore/getting-started/intro-to-ef-core.md | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/content/efcore/getting-started/README.md b/content/efcore/getting-started/README.md index 5d928e7..7a94e34 100644 --- a/content/efcore/getting-started/README.md +++ b/content/efcore/getting-started/README.md @@ -2,7 +2,7 @@ ## Who Should Read This? -This tutorial is aimed at people who are learning EF Core for the first time. More advanced functionality is covered in the [docs](https://docs.efproject.net/en/latest/). Before beginning this tutorial, you should understand the following topics: +This tutorial is aimed at people who are learning EF Core for the first time. More advanced functionality is covered in the [docs](https://docs.microsoft.com/en-us/ef/). Before beginning this tutorial, you should understand the following topics: - C# (see [Getting Started with C#](https://www.microsoft.com/net/tutorials/csharp/getting-started)) - Relational database concepts diff --git a/content/efcore/getting-started/installing-ef-core.md b/content/efcore/getting-started/installing-ef-core.md index 5655e36..f59da77 100644 --- a/content/efcore/getting-started/installing-ef-core.md +++ b/content/efcore/getting-started/installing-ef-core.md @@ -22,7 +22,7 @@ dotnet new # Initialize .NET Core project (generates Startup.cs and p ## Add EF Core to Project -To add EF Core to your project, you need to list it as a dependency in your `project.json` file. You need to add the appropriate package for your database provider as well. See [Database Providers](https://docs.efproject.net/en/latest/providers/index.html) in the docs for a full listing of available database providers. In this example, we use Sqlite. +To add EF Core to your project, you need to list it as a dependency in your `project.json` file. You need to add the appropriate package for your database provider as well. See [Database Providers](https://docs.microsoft.com/en-us/ef/core/providers/) in the docs for a full listing of available database providers. In this example, we use Sqlite. ```json "dependencies": diff --git a/content/efcore/getting-started/intro-to-ef-core.md b/content/efcore/getting-started/intro-to-ef-core.md index d52f84c..510c446 100644 --- a/content/efcore/getting-started/intro-to-ef-core.md +++ b/content/efcore/getting-started/intro-to-ef-core.md @@ -2,8 +2,8 @@ Entity Framework Core (EF Core) is a lightweight, extensible, and cross-platform version of Entity Framework. Entity Framework is an object-relational mapper (O/RM) that enables .NET developers to work with a database using .NET objects. This allows developers to create and manage databases without most of the data-access code that developers usually need to write.  -EF Core and the latest version of Entity Framework (EF6.x) differ in the features they support. A comparison of the features supported by each can be found on the [feature comparison page](https://docs.efproject.net/en/latest/efcore-vs-ef6/features.html) of the docs. If you want help determining which version is best for your project, check out the ["Which One Is Right for You?"](https://docs.efproject.net/en/latest/efcore-vs-ef6/choosing.html) page. +EF Core and the latest version of Entity Framework (EF6.x) differ in the features they support. A comparison of the features supported by each can be found on the [feature comparison page](https://docs.microsoft.com/en-us/ef/efcore-and-ef6/features) of the docs. If you want help determining which version is best for your project, check out the ["Which One Is Right for You?"](https://docs.microsoft.com/en-us/ef/efcore-and-ef6/choosing) page. ## Database Providers -At the moment, EF Core only supports relational databases, but there are plans to add support for non-relational databases in the future. Supported database providers are listed on the [Database Providers page](https://docs.efproject.net/en/latest/providers/index.html) in the docs. \ No newline at end of file +At the moment, EF Core only supports relational databases, but there are plans to add support for non-relational databases in the future. Supported database providers are listed on the [Database Providers page](https://docs.microsoft.com/en-us/ef/core/providers/) in the docs. From ddfce97a12f69e0a8eb11e1ff5df0cfdbd841671 Mon Sep 17 00:00:00 2001 From: deakgeek Date: Tue, 29 Nov 2016 17:40:57 -0600 Subject: [PATCH 17/22] Resolves #29 - Change Query Tutorial Genre --- content/efcore/getting-started/querying.md | 6 +++--- .../getting-started/samples/filtering-entities/Program.cs | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/content/efcore/getting-started/querying.md b/content/efcore/getting-started/querying.md index eee5cdf..4647caa 100644 --- a/content/efcore/getting-started/querying.md +++ b/content/efcore/getting-started/querying.md @@ -59,18 +59,18 @@ Once we have an instance of the context, we can use it to interact with the data ## Filtering Entities -Loading all of the entities from a database is useful, but there are many use cases where we only want to load a subset of the entities from the database. For example, we may want to filter books by author or genre. EF Core allows us to filter entities via the `Where` extension method. Let's look at an example where we retrieve all science fiction books from the database. +Loading all of the entities from a database is useful, but there are many use cases where we only want to load a subset of the entities from the database. For example, we may want to filter books by author or genre. EF Core allows us to filter entities via the `Where` extension method. Let's look at an example where we retrieve all Historical books from the database. ```c# using (var context = new LibraryContext()) { var books = context.Books - .Where(b => b.Genre == "Science Fiction") + .Where(b => b.Genre == "Historical") .ToList(); } ``` -We use a lambda expression within the `Where` method to detect if the `Genre` property of each book is equal to "Science Fiction". Books that meet the criteria of the lambda expression will be included in the final result, while books that do not will be excluded. +We use a lambda expression within the `Where` method to detect if the `Genre` property of each book is equal to "Historical". Books that meet the criteria of the lambda expression will be included in the final result, while books that do not will be excluded. We could retrieve all of the books like in the previous example and then filter them in our application; however, this would require us to load all of the books into memory, and it does not allow us to take advantage of our database's optimized querying functionality. Allowing the database to do what it does best and perform the filtering for us results in a significant performance increase. Thus, it is important that we filter the `DbSet` with the `Where` method before calling `ToList`. diff --git a/content/efcore/getting-started/samples/filtering-entities/Program.cs b/content/efcore/getting-started/samples/filtering-entities/Program.cs index 1750d01..1e05ed9 100644 --- a/content/efcore/getting-started/samples/filtering-entities/Program.cs +++ b/content/efcore/getting-started/samples/filtering-entities/Program.cs @@ -9,7 +9,7 @@ public static void Main() using (var context = new LibraryContext()) { var books = context.Books - .Where(s => s.Genre.Contains("Science Fiction")) + .Where(b => b.Genre == "Historical") .ToList(); foreach (Book book in books) From 0c036fd06148805239367302afcc991063580e46 Mon Sep 17 00:00:00 2001 From: deakgeek Date: Tue, 6 Dec 2016 16:59:22 -0600 Subject: [PATCH 18/22] Resolves #35 Updates loading single entity example to use letter b instead of s --- .../getting-started/samples/loading-single-entity/Program.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/content/efcore/getting-started/samples/loading-single-entity/Program.cs b/content/efcore/getting-started/samples/loading-single-entity/Program.cs index 87f69cc..c0a1c52 100644 --- a/content/efcore/getting-started/samples/loading-single-entity/Program.cs +++ b/content/efcore/getting-started/samples/loading-single-entity/Program.cs @@ -9,7 +9,7 @@ public static void Main() using (var context = new LibraryContext()) { var book = context.Books - .Single(s => s.BookId == 1); + .Single(b => b.BookId == 1); Console.WriteLine(book.Title); } } From 616777a0c994ba7081041a2953a49611d267414a Mon Sep 17 00:00:00 2001 From: deakgeek Date: Tue, 6 Dec 2016 18:25:03 -0600 Subject: [PATCH 19/22] Resolves #34 - Update LibraryContext.cs to use DBHelper --- .../efcore/getting-started/samples/shared/LibraryContext.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/content/efcore/getting-started/samples/shared/LibraryContext.cs b/content/efcore/getting-started/samples/shared/LibraryContext.cs index 236a464..4c169bf 100644 --- a/content/efcore/getting-started/samples/shared/LibraryContext.cs +++ b/content/efcore/getting-started/samples/shared/LibraryContext.cs @@ -1,5 +1,6 @@ using Microsoft.EntityFrameworkCore; using System.Collections.Generic; +using REPLHelper; public class LibraryContext : DbContext { @@ -8,6 +9,6 @@ public class LibraryContext : DbContext protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) { - optionsBuilder.UseSqlite("Filename=Library.db"); + optionsBuilder.UseSqlite(DBHelper.GetReadonlyDbConnectionString()); } } \ No newline at end of file From 1240ac6d5a8441f02e0a1757db892dd658fc0cbb Mon Sep 17 00:00:00 2001 From: Ryan Helmoski Date: Wed, 7 Dec 2016 14:38:30 -0600 Subject: [PATCH 20/22] Resolves #41 - missing brace (#43) --- content/efcore/getting-started/installing-ef-core.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/content/efcore/getting-started/installing-ef-core.md b/content/efcore/getting-started/installing-ef-core.md index f59da77..2e90330 100644 --- a/content/efcore/getting-started/installing-ef-core.md +++ b/content/efcore/getting-started/installing-ef-core.md @@ -24,8 +24,8 @@ dotnet new # Initialize .NET Core project (generates Startup.cs and p To add EF Core to your project, you need to list it as a dependency in your `project.json` file. You need to add the appropriate package for your database provider as well. See [Database Providers](https://docs.microsoft.com/en-us/ef/core/providers/) in the docs for a full listing of available database providers. In this example, we use Sqlite. -```json -"dependencies": +```{json} +"dependencies": { "Microsoft.EntityFrameworkCore.Sqlite": "1.0.0", "Microsoft.EntityFrameworkCore.Design": { "version": "1.0.0-preview2-final", From d3dc8118a0e8821492bac490b1bfc66ea34d68bf Mon Sep 17 00:00:00 2001 From: Ryan Helmoski Date: Thu, 8 Dec 2016 15:37:17 -0600 Subject: [PATCH 21/22] Resolves #39 - updates tutorials to support multiple files --- content/efcore/getting-started/querying.md | 23 ++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/content/efcore/getting-started/querying.md b/content/efcore/getting-started/querying.md index 4647caa..63295b5 100644 --- a/content/efcore/getting-started/querying.md +++ b/content/efcore/getting-started/querying.md @@ -26,7 +26,8 @@ For this lesson, we will use a small database to allow you to try querying on yo | 15 | 8 | Murder on the Orient Express | Mystery | 1934 | | 16 | 1 | The Call of the Wild | Adventure | 1903 | | 17 | 4 | Death Comes for the Archbishop | Historical | 1927 | - + + ### Authors | AuthorId | FirstName | LastName | |----------|------------|-----------| @@ -46,12 +47,14 @@ For this lesson, we will use a small database to allow you to try querying on yo Let's say we want to get all of the books from our database in a C# application. Normally, we would have to write a database query in a domain-specific language, such as SQL, and then we would have to manually map the results of this query to C# objects. With EF Core, this process is much easier because it takes care of the data access code for us. -```c# +```{.snippet} using (var context = new LibraryContext()) { var books = context.Books.ToList(); } -``` +``` +:::repl{data-name=loading-all-entities} +::: In order to interact with the database via EF Core, we must first create an instance of our context (`LibraryContext`). Notice that we create the context with the `using` keyword. This automatically disposes the context after the using block has finished executing. Alternatively, we could manually call `LibraryContext.dispose()`, but the `using` method is more convenient and readable. It is imperative that we dispose of the context after we are finished using it because it holds an open connection to the database. @@ -61,14 +64,16 @@ Once we have an instance of the context, we can use it to interact with the data Loading all of the entities from a database is useful, but there are many use cases where we only want to load a subset of the entities from the database. For example, we may want to filter books by author or genre. EF Core allows us to filter entities via the `Where` extension method. Let's look at an example where we retrieve all Historical books from the database. -```c# +```{.snippet} using (var context = new LibraryContext()) { var books = context.Books .Where(b => b.Genre == "Historical") .ToList(); } -``` +``` +:::repl{data-name=filtering-entities} +::: We use a lambda expression within the `Where` method to detect if the `Genre` property of each book is equal to "Historical". Books that meet the criteria of the lambda expression will be included in the final result, while books that do not will be excluded. @@ -78,12 +83,14 @@ We could retrieve all of the books like in the previous example and then filter Both of our examples so far have shown how to retrieve a collection of entities. Let's look at how to retrieve a single entity based on a unique identifier. -```c# +```{.snippet} using (var context = new LibraryContext()) { var book = context.Books .Single(b => b.Id == 1); } -``` +``` +:::repl{data-name=loading-single-entity} +::: -In this example, we use the `Single` extension method to find the book with an `Id` of 1. Note that we do not need to call `ToList()` because `Single` returns a single entity. It is important to only use `Single` with unique identifiers because if multiple entities meet the success criteria a `System.InvalidOperationException` will be thrown. \ No newline at end of file +In this example, we use the `Single` extension method to find the book with an `Id` of 1. Note that we do not need to call `ToList()` because `Single` returns a single entity. It is important to only use `Single` with unique identifiers because if multiple entities meet the success criteria a `System.InvalidOperationException` will be thrown. From 88d59fdd79f27e74330ff5c5417ffdb93128a51b Mon Sep 17 00:00:00 2001 From: abadami Date: Thu, 8 Dec 2016 16:02:04 -0600 Subject: [PATCH 22/22] Remove a question mark to help standardize the target audience header "Who Should Read This" --- content/efcore/getting-started/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/content/efcore/getting-started/README.md b/content/efcore/getting-started/README.md index 7a94e34..3ba7914 100644 --- a/content/efcore/getting-started/README.md +++ b/content/efcore/getting-started/README.md @@ -1,6 +1,6 @@ # Getting Started with Entity Framework Core -## Who Should Read This? +## Who Should Read This This tutorial is aimed at people who are learning EF Core for the first time. More advanced functionality is covered in the [docs](https://docs.microsoft.com/en-us/ef/). Before beginning this tutorial, you should understand the following topics: