From cd1fa67960f6af1671064bb93aef86532d1697e4 Mon Sep 17 00:00:00 2001 From: Marcello Lamonaca Date: Sat, 8 May 2021 11:46:09 +0200 Subject: [PATCH] Add notes on DbContext Nullability --- .NET/Database/EntityFramework.md | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/.NET/Database/EntityFramework.md b/.NET/Database/EntityFramework.md index 9308482..a946b87 100644 --- a/.NET/Database/EntityFramework.md +++ b/.NET/Database/EntityFramework.md @@ -30,7 +30,8 @@ namespace .Model NuGet Packages to install: - `Microsoft.EntityFrameworkCore` -- `Microsoft.EntityFrameworkCore.Tools` to use migrations +- `Microsoft.EntityFrameworkCore.Tools` to use migrations in Visual Studio +- `Microsoft.EntityFrameworkCore.Tools.DotNet` to use migrations in `dotnet` cli (`dotnet-ef`) - `Microsoft.EntityFrameworkCore.Design` *or* `Microsoft.EntityFrameworkCore..Design` needed for tools to work (bundled w\ tools) - `Microsoft.EntityFrameworkCore.` @@ -39,15 +40,6 @@ using Microsoft.EntityFrameworkCore; namespace .Model { - class Context : DbContext - { - public Context(DbContextOptions options) : base(options) - { - } - } - - // or - class Context : DbContext { private const string _connectionString = "Server=;Database=;UID=;Pwd="; @@ -58,8 +50,15 @@ namespace .Model optionsBuilder.UseSqlServer(_connectionString); // specify connection } + // or + + public Context(DbContextOptions options) : base(options) + { + } + //DBSet represents the collection of all entities in the context (or that can be queried from the database) of a given type public DbSet Entities { get; set; } + public DbSet Entities => Set(); // with nullable reference types } } ```