• The DBContext is a short lived instance, designed for a single unit of work, after which the entity framework provider takes care of disposing.
  • When creating a dbcontext at application level, simply derive from DbContext and have public constructor that takes a DbContextOptions. (DbContextOptions options)
  • EF provides 2 ways to sync the db context to the database
    1. From code to databse => use Migration
    2. From database to code => use Reverse Engineering - eg Scaffold from DBContext
  • Install Microsoft.EntityFrameworkCore.SqlServer from Nuget into the target project ie the project that will host your db context and other db elements.
  • Install Microsoft.EntityFrameworkCore.Tools as an alternative to installing dotnet ef globally.
  • Local connection string options.UseSqlServer(“Data Source=.;Initial Catalog=EfTest;Integrated Security=True;”);
  • Running the dotnet ef cli without installing Microsoft.EntityFrameworkCore.Tools resulted in the following exception: Your startup project ‘WebAppEfCore’ doesn’t reference Microsoft.EntityFrameworkCore.Design. This package is required for the Entity Framework Core Tools to work. Ensure your startup project is correct, install the package, and try again.
  • Trying a ASP.NET Web Application without a DbContext No DbContext was found in assembly ‘WebAppEfCore’. Ensure that you’re using the correct assembly and that the type is neither abstract nor generic.