using System;
using Microsoft.EntityFrameworkCore;
using MyShop.Models;
using Microsoft.EntityFrameworkCore.Design;
namespace MyShop.Data
{
public class ApplicationDbContext: DbContext
{
public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options) :
base(options)
{
}
public DbSet<Category> Category { get; set; }
}
}
dotnet ef migrations add CategoryToDatabase
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace MyShop.Migrations
{
public partial class CategoryToDatabase : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "Category",
columns: table => new
{
Id = table.Column<string>(type: "nvarchar(450)", nullable: false),
Name = table.Column<string>(type: "nvarchar(max)", nullable: false),
DisplayOrder = table.Column<int>(type: "int", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Category", x => x.Id);
});
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "Category");
}
}
}
dotnet ef database update
{
"ConnectionStrings": {
"DefaultConnection": "Server=localhost;Database=MyShop;Trusted_Connection=True;User Id=SA,Password=P@ssswo1rd"
},
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*"
}
-v
:info: Microsoft.EntityFrameworkCore.Infrastructure[10403]
Entity Framework Core 6.0.10 initialized 'ApplicationDbContext' using provider 'Microsoft.EntityFrameworkCore.SqlServer:6.0.10' with options: None
Finding design-time services referenced by assembly 'MyShop'...
Finding design-time services referenced by assembly 'MyShop'...
No referenced design-time services were found.
Finding design-time services for provider 'Microsoft.EntityFrameworkCore.SqlServer'...
Using design-time services from provider 'Microsoft.EntityFrameworkCore.SqlServer'.
Finding IDesignTimeServices implementations in assembly 'MyShop'...
No design-time services were found.