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 } } ```