Giter Club home page Giter Club logo

efcoreinaction's Introduction

EfCoreInAction

Welcome to the Git repo that is associated with the book Entity Framework Core in Action published by Manning Publications. This book details how to use Entity Framework Core (EF Core) to develop database access code in .NET Core applications.

This Git repo contains all the code in the book, plus an example book selling site that I develop, and improve, in the book. All the code uses Microsoft's, open-source Entity Framework Core library for database access.

NOTE: Code uses .NET Core 2.0, with a few branches converted to .NET Core 2.1
See Where's the code.

To run the changed Git repo code you need to:

  1. Install .NET Core 2.0 SDK – go to https://www.microsoft.com/net/download/core and select the correct SDK for your system
  2. I recommend updating to Visual Studio 2017 15.3 or later as that has the new templates for ASP.NET Core 2.0.0. Or use Visual Studio code (the code is designed to work with either VS2017 or VSCode)

Where's the code!

This repo has a branch-per-chapter, and sometime and branch-per-section, approach so if you are looking at the master branch then you won't see any code! Just click the Branches on the site and you will find all the branches I have created so far.

Map of the branches

The branches mainly inherit from each other (shown as --> in the diagram) but a few are on there own, like master and Chapter01 (shown with spaces between them). The ones that are build for deployment to a web site are branches off the main stem (shown as higher offshoots). I did that because I built the normal code so you can run it locally without migrations.
Note: to fit the diagram in I shorten the real branch names and use Ch4 instead of Chapter04

Part 1 - Getting started

                                        Ch5Migrate
                                          /
master    Ch1    Ch2 --> Ch3 --> Ch4 --> Ch5 -->

Part 2 - Entity Framework in depth

(ch5) --> Ch6 --> Ch7 --> Ch8 --> Ch9

Part 3 - Using Entity Framework in real-world applications

                                           Ch13-Part3
                                              /
                                        Ch13-Part2    Ch14MySql
                                            /         /
(ch9) --> Ch10 --> Ch11 --> Ch12 --> Ch13-Part1 --> Ch14  --> (Ch15) Note1

Note1: Chapter 15, on unit testing has its own Git repo https://github.com/JonPSmith/EfCore.TestSupport and a NuGet package called EfCore.TestSupport.

NET Core 2.1 examples

I wanted to compare the performance of EF Core 2.0 and EF Core 2.1, so I created a few new branches. Here is the list:

  • Chapter05-NetCore21
  • Chapter13-Part1-NetCore21
  • Chapter13-Part2-NetCore21

NET Core 3 examples

To support EF Core 3 I created new branches. They are there to help you if you want to work with EF Core 3. I also used the Chapter13-Part3-NetCore3 branch to find all the changes between EF Core 2 and EF Core 3 (the unit tests are very helpful for that). Here is the list:

  • Chapter01-NetCore3
  • Chapter05-NetCore3
  • Chapter13-Part3-NetCore3

Live example book selling site

You can find a live verison of the example books selling site. This provides an online example of the site to look at. You can't edit the data on the live site for obvious reasons, but you can if you clone the git this Git repo and run the example application locally. You can 'buy a book' though on the live site, and even see your old 'purchases'.

The Logs navigation button will show you the SQL code that EF Core used to implement the last command you used.

Diagram of site

Note: The admin button is missing on the live site.

Database naming conventions

Because the database structure can change in each branch I use a system of building the database name using the branch name from a file which is written by a small gulpfile that is run by Visual Studio # on every build.

Also I use xUnit unit tests which run in parallel, so I cannot use one database for all the tests, as they would all be changing the database at one time. I therefore use another system to append the test class name, and sometimes the method that ran. This is all explained in chapter 11, but I wanted to warn you you will get lots of databases if you run the unit tests.

If you get fed up with all databases there is a unit test in test/UnitCommands/DeleteAllUnitTestDatabases that will delete all the unit test databases in the branch you are in.

Licence

MIT

Other links

My twitter handle is @thereformedprog.
My blog site is at http://www.thereformedprogrammer.net/ where you will find articles on EF 6.x and some on EF Core.

Happy coding!

efcoreinaction's People

Contributors

jonpsmith avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

efcoreinaction's Issues

Book image missing in confirmed order in chapter 4

Just a minor thing overall, but anyway:

The book icon is showing only a broken image on the confirmed order page after checkout. That's because OneOrderPartial.cshtml in line 15 is setting the source to "#" instead of "@lineItem.ImageUrl". In addition there are books without image URLs, so a check if it's not null is necessary I guess. The same problem in ListBasketPartial.cshtml where the image source is set to "#" when it's null.

The ImageUrl needs to be set in DisplayOrderService.cs in line 60 or so as well with "ImageUrl = lineItem.ChosenBook.ImageUrl," to be loaded in the OrderListDTO

Confusing about the book content page 84

Hi Jon,
I love your book and the way that you explained is easy to me to understand. However, there is a concern I still need to confirm. In the page 84 of the book, there is a sentence :
Also, the Find method isn’t affected by a model-level filter.

So what you means is we can actually get the soft-deleted item by using Find method? Can you share any resource that mentioned about it?

Thank you very much.

Upgrading this repo to .Net Core 3.0

Hi @JonPSmith , how are you?

Thank you for a wonderful book on the EF Core.

As EF Core 3.0 is GA now, will you be releasing -

  1. A new edition of your book that refers to EF Core 3.0 and
  2. Updated version of this GitHub repo that works with EF Core 3.0 ?

Thank you.

Inconsistent connection string

The connection string shown in page 14

private const string ConnectionString =
@” Server = (local db)\nssql local dv;
Database=MyFirstEfCoreDb;
Trusted_Connection=True”;

is inconsistent with the one used in the code hosted in the git.

        private const string ConnectionString =           
            @"Server=(localdb)\mssqllocaldb;
             Database=MyFirstEfCoreDb;
             Trusted_Connection=True";

Chapter 2 - Compiling in VS 2019

Hi Jon,

I just started reading this book. Really appreciate the detailed explanations on EFCore. I've downloaded the entire source code for Chapter 2 but unable to compile in VS 2019, .NET Core 3.1. Do you have any guideline on how do we migrate the codes from VS 2017 to VS 2019? Thanks.

Regards,

Jordan Lim

Microsoft.EntityFrameworkCore.DbUpdateConcurrencyException

Hey Jon
I am getting this Exception when I am trying to update ICollection<Reviews>

'Database operation expected to affect 1 row(s) but actually affected 0 row(s). Data may have been modified or deleted since entities were loaded

I have tried many solutions . but not worked !!

could you please help me ?

Is checking !db.Books.Any() necessary after EnsureDeleted followed by EnsureCreated?

I am reading the chapter one right now. I found the WipeCreateSeed as follows:

db.Database.EnsureDeleted();
db.Database.EnsureCreated();
if (!db.Books.Any())
{
   WriteTestData(db);
   Console.WriteLine("Seeded database");
}

My question: Is if (!db.Books.Any()) necessary here? We already have a brand new database before if (!db.Books.Any()) so !db.Books.Any() always return true, IMHO.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.