EF Core - Các lệnh PMC
Sử dụng các lệnh của Package Manager Console Commands cho Migrations
Các lệnh mifration trong EF Core được sử dụng trong Package Manager Console. Mở Package Manager Console từ menu Tools -> NuGet Package Manger -> Package Manager Console
Danh sách các lệnh:
Lệnh PMC | Ý nghĩa |
---|---|
Get-Help entityframework | Hiển thị thông tin về các lệnh của EF. |
Add-Migration <migration name> | Tạo ra một migration bằng cách thêm một migration snapshot. |
Remove-Migration | Xóa migration snapshot mới nhất. |
Update-Database | Cập nhật cơso73 dữ liệu dựa vào migration snapshot mới nhất. |
Script-Migration | Tạo ra một script SQL bằng cách sử dụng tất cả migration snapshots. |
Scaffold-DbContext | Tạo ra một DbContext và các lớp có kiểu thực thể cho cơ sở dữ liệu. Đây được gọi là kỹ thuật đảo ngược. |
Get-DbContext | Lấy thông tin về kiểu dữ liệu DbContext . |
Drop-Database | Xóa cơ sở dữ liệu. |
Get-Help
PM> get-help entityframework
Kết quả:
_/\__
---==/ \\
___ ___ |. \|\
| __|| __| | ) \\\
| _| | _| \_/ | //|\\
|___||_| / \\\/\\
TOPIC
about_EntityFrameworkCore
SHORT DESCRIPTION
Provides information about the Entity Framework Core Package Manager Console Tools.
LONG DESCRIPTION
This topic describes the Entity Framework Core Package Manager Console Tools.
See https://docs.efproject.net for information on Entity Framework Core.
The following Entity Framework Core commands are available.
Cmdlet Description
-------------------------- ---------------------------------------------------
Add-Migration Adds a new migration.
Drop-Database Drops the database.
Get-DbContext Gets information about a DbContext type.
Remove-Migration Removes the last migration.
Scaffold-DbContext Scaffolds a DbContext and entity types for a database.
Script-Migration Generates a SQL script from migrations.
Update-Database Updates the database to a specified migration.
SEE ALSO
Add-Migration
Drop-Database
Get-DbContext
Remove-Migration
Scaffold-DbContext
Script-Migration
Update-Database
Add-Migration
NAME
Add-Migration
SYNOPSIS
Adds a new migration.
SYNTAX
Add-Migration [-Name] <String> [-OutputDir <String>] [-Context <String>] [-Project <String>]
[-StartupProject <String>] [<CommonParameters>]
DESCRIPTION
Adds a new migration.
REMARKS
To see the examples, type: "get-help Add-Migration -examples".
For more information, type: "get-help Add-Migration -detailed".
For technical information, type: "get-help Add-Migration -full".
Remove-Migration
NAME
Remove-Migration
SYNOPSIS
Removes the last migration.
SYNTAX
Remove-Migration [-Force] [-Context <String>] [-Project <String>] [-StartupProject <String>]
[<CommonParameters>]
DESCRIPTION
Removes the last migration.
RELATED LINKS
Add-Migration
about_EntityFrameworkCore
REMARKS
To see the examples, type: "get-help Remove-Migration -examples".
For more information, type: "get-help Remove-Migration -detailed".
For technical information, type: "get-help Remove-Migration -full".
Update-Database
NAME
Update-Database
SYNOPSIS
Updates the database to a specified migration.
SYNTAX
Update-Database [[-Migration] <String>] [-Context <String>] [-Project <String>]
[-StartupProject <String>] [<CommonParameters>]
DESCRIPTION
Updates the database to a specified migration.
RELATED LINKS
Script-Migration
about_EntityFrameworkCore
REMARKS
To see the examples, type: "get-help Update-Database -examples".
For more information, type: "get-help Update-Database -detailed".
For technical information, type: "get-help Update-Database -full".
Script-migration
NAME
Script-Migration
SYNOPSIS
Generates a SQL script from migrations.
SYNTAX
Script-Migration [-From] <String> [-To] <String> [-Idempotent] [-Output <String>]
[-Context <String>] [-Project <String>] [-StartupProject <String>]
[<CommonParameters>]
Script-Migration [[-From] <String>] [-Idempotent] [-Output <String>] [-Context <String>]
[-Project <String>] [-StartupProject <String>] [<CommonParameters>]
DESCRIPTION
Generates a SQL script from migrations.
RELATED LINKS
Update-Database
about_EntityFrameworkCore
REMARKS
To see the examples, type: "get-help Script-Migration -examples".
For more information, type: "get-help Script-Migration -detailed".
For technical information, type: "get-help Script-Migration -full".
scaffold-dbcontext
NAME
Scaffold-DbContext
SYNOPSIS
Scaffolds a DbContext and entity types for a database.
SYNTAX
Scaffold-DbContext [-Connection] <String> [-Provider] <String> [-OutputDir <String>]
[-Context <String>] [-Schemas <String[]>] [-Tables <String[]>]
[-DataAnnotations] [-Force] [-Project <String>] [-StartupProject <String>]
[<CommonParameters>]
DESCRIPTION
Scaffolds a DbContext and entity types for a database.
RELATED LINKS
about_EntityFrameworkCore
REMARKS
To see the examples, type: "get-help Scaffold-DbContext -examples".
For more information, type: "get-help Scaffold-DbContext -detailed".
For technical information, type: "get-help Scaffold-DbContext -full".
Get-DbContext
NAME
Get-DbContext
SYNOPSIS
Gets information about a DbContext type.
SYNTAX
Get-DbContext [-Context <String>] [-Project <String>] [-StartupProject <String>]
[<CommonParameters>]
DESCRIPTION
Gets information about a DbContext type.
RELATED LINKS
about_EntityFrameworkCore
REMARKS
To see the examples, type: "get-help Get-DbContext -examples".
For more information, type: "get-help Get-DbContext -detailed".
For technical information, type: "get-help Get-DbContext -full".
Drop-Database
NAME
Drop-Database
SYNOPSIS
Drops the database.
SYNTAX
Drop-Database [-Context <String>] [-Project <String>] [-StartupProject <String>]
[-WhatIf] [-Confirm] [<CommonParameters>]
DESCRIPTION
Drops the database.
RELATED LINKS
Update-Database
about_EntityFrameworkCore
REMARKS
To see the examples, type: "get-help Drop-Database -examples".
For more information, type: "get-help Drop-Database -detailed".
For technical information, type: "get-help Drop-Database -full".