Learn about all EF Core commands for dotnet CLI (Command Line Interface) such as dotnet ef database, dotnet ef dbcontext, and dotnet ef migrations.
EFBasics
EFCore
EF6DB-First
EF6Code-First
FAQs
EFQuiz
EFResources
CheatSheet
More
✕
EntityFrameworkTutorials
EFCore
EF6Code-First
EF6DB-First
EntityFramework
EFQuiz
FAQs
EFResources
EFCheatSheet
EFCore-Introduction
EFCore-Installation
EFCore-ExistingDatabase
EFCore-DbContext
EFCore-FirstApplication
EFCore-Querying
EFCore-SavingData
EFCore-Conventions
One-to-ManyConventions
One-to-OneConventions
EFCore-Configurations
EFCore-FluentAPI
ConfigureOne-to-ManyRelationship
ConfigureOne-to-OneRelationship
ConfigureMany-to-ManyRelationship
DisconnectedScenario:InsertData
UpdateData
DeleteData
ChangeTracker
ShadowProperty
WorkingwithDisconnectedEntityGraph
TrackingEntityGraph
RawSQLQueries
WorkingwithStoredProcedure
Logging
Migration
PMCCommands
CLICommands
Previous
Home
CommandLineInterfaceCommandsforMigrations
Use.NETCoreCommandListInterfacetoexecuteentityframeworkcorecommands.Touse.NETCLI,addundernodebyeditingyour.NETCoreproject's.csprojfile.
Opencommandpromptandnavigatetoyourproject'srootfolderandenterdotnetef--helptolistEFCorecommands,asshownbelow.
C:>dotnetef--help
EntityFrameworkCore.NETCommandLineTools2.0.0-rtm-26452
Usage:dotnetef[options][command]
Options:
--versionShowversioninformation
-h|--helpShowhelpinformation
-v|--verboseShowverboseoutput.
--no-colorDon'tcolorizeoutput.
--prefix-outputPrefixoutputwithlevel.
Commands:
databaseCommandstomanagethedatabase.
dbcontextCommandstomanageDbContexttypes.
migrationsCommandstomanagemigrations.
Use"dotnetef[command]--help"formoreinformationaboutacommand.
Asyoucanseeabove,therearethreemainEFcommandsavailable:database,dbcontextandmigrations.ThefollowingtablelistsallEFcommandsandsubcommands.
Command
SubCommands
Usage
Database
drop
Dropsthedatabase.
update
Updatesthedatabasetoaspecifiedmigration.
DbContext
info
GetsinformationaboutaDbContexttype.
list
ListsavailableDbContexttypes.
scaffold
ScaffoldsaDbContextandentitytypesforadatabase.
Migrations
add
Addsanewmigration.
list
Listsavailablemigrations.
remove
Removesthelastmigration.
script:
GeneratesaSQLscriptfrommigrations.
Let'sseeavailableoptionsforeachcommand.
DatabaseDrop
>dotnetefdatabasedrop
Usage:dotnetefdatabasedrop[options]
Options:
-f|--forceDon'tconfirm.
--dry-runShowwhichdatabasewouldbedropped,butdon'tdropit.
-c|--contextTheDbContexttouse.
-p|--projectTheprojecttouse.
-s|--startup-projectThestartupprojecttouse.
--frameworkThetargetframework.
--configurationTheconfigurationtouse.
--runtimeTheruntimetouse.
--msbuildprojectextensionspathTheMSBuildprojectextensionspath.Defaultsto"obj".
--no-buildDon'tbuildtheproject.Onlyusethiswhen
thebuildisup-to-date.
DatabaseUpdate
>dotnetefdatabaseupdate
Usage:dotnetefdatabaseupdate[arguments][options]
Arguments:
<MIGRATION>Thetargetmigration.If'0',allmigrationswillbereverted.De
faultstothelastmigration.
Options:
-c|--contextTheDbContexttouse.
-p|--projectTheprojecttouse.
-s|--startup-projectThestartupprojecttouse.
--frameworkThetargetframework.
--configurationTheconfigurationtouse.
--runtimeTheruntimetouse.
--msbuildprojectextensionspathTheMSBuildprojectextensionspath.Defaultsto"obj".
--no-buildDon'tbuildtheproject.Onlyusethiswhen
thebuildisup-to-date.
DbContextInfo
>dotnetefdbcontextinfo
Usage:dotnetefdbcontextinfo[options]
Options:
--jsonShowJSONoutput.
-c|--contextTheDbContexttouse.
-p|--projectTheprojecttouse.
-s|--startup-projectThestartupprojecttouse.
--frameworkThetargetframework.
--configurationTheconfigurationtouse.
--runtimeTheruntimetouse.
--msbuildprojectextensionspathTheMSBuildprojectextensionspath.Defaultsto"obj".
--no-buildDon'tbuildtheproject.Onlyusethis
whenthebuildisup-to-date.
DbContextList
>dotnetefdbcontextlist
Usage:dotnetefdbcontextlist[options]
Options:
--jsonShowJSONoutput.
-p|--projectTheprojecttouse.
-s|--startup-projectThestartupprojecttouse.
--frameworkThetargetframework.
--configurationTheconfigurationtouse.
--runtimeTheruntimetouse.
--msbuildprojectextensionspathTheMSBuildprojectextensionspath.Defaultsto"obj".
--no-buildDon'tbuildtheproject.Onlyusethis
whenthebuildisup-to-date.
DbContextScaffold
>dotnetefdbcontextscaffold
Usage:dotnetefdbcontextscaffold[arguments][options]
Arguments:
Theconnectionstringtothedatabase.
Theprovidertouse.(E.g.Microsoft.EntityFrameworkCore.SqlServ
er)
Options:
-d|--data-annotationsUseattributestoconfigurethemodel(
wherepossible).Ifomitted,onlythefluentAPIisused.
-c|--contextThenameoftheDbContext.
-f|--forceOverwriteexistingfiles.
-o|--output-dirThedirectorytoputfilesin.Pathsar
erelativetotheprojectdirectory.
--schema...Theschemasoftablestogenerateentit
ytypesfor.
-t|--table>TABLE_NAME<...thetablestogenerateentitytypesfor.>Theprojecttouse.
-s|--startup-projectThestartupprojecttouse.
--frameworkThetargetframework.
--configurationTheconfigurationtouse.
--runtimeTheruntimetouse.
--msbuildprojectextensionspathTheMSBuildprojectextensionspath.Defaultsto"obj".
--no-buildDon'tbuildtheproject.Onlyusethis
whenthebuildisup-to-date.
Add
>dotnetefmigrationsadd
Usage:dotnetefmigrationsadd[arguments][options]
Arguments:
<NAME>Thenameofthemigration.
Options:
-o|--output-dirThedirectory(andsub-namespace)tous
e.Pathsarerelativetotheprojectdirectory.Defaultsto"Migrations".
--jsonShowJSONoutput.
-c|--contextTheDbContexttouse.
-p|--projectTheprojecttouse.
-s|--startup-projectThestartupprojecttouse.
--frameworkThetargetframework.
--configurationTheconfigurationtouse.
--runtimeTheruntimetouse.
--msbuildprojectextensionspathTheMSBuildprojectextensionspath.Defaultsto"obj".
--no-buildDon'tbuildtheproject.Onlyusethis
whenthebuildisup-to-date.
List
>dotnetefmigrationslist
Usage:dotnetefmigrationslist[options]
Options:
--jsonShowJSONoutput.
-c|--contextTheDbContexttouse.
-p|--projectTheprojecttouse.
-s|--startup-projectThestartupprojecttouse.
--frameworkThetargetframework.
--configurationTheconfigurationtouse.
--runtimeTheruntimetouse.
--msbuildprojectextensionspathTheMSBuildprojectextensionspath.Defaultsto"obj".
--no-buildDon'tbuildtheproject.Onlyusethis
whenthebuildisup-to-date.
Remove
>dotnetefmigrationsremove
Usage:dotnetefmigrationsremove[options]
Options:
-f|--forceDon'tchecktoseeifthemigrationhas
beenappliedtothedatabase.
--jsonShowJSONoutput.
-c|--contextTheDbContexttouse.
-p|--projectTheprojecttouse.
-s|--startup-projectThestartupprojecttouse.
--frameworkThetargetframework.
--configurationTheconfigurationtouse.
--runtimeTheruntimetouse.
--msbuildprojectextensionspathTheMSBuildprojectextensionspath.Defaultsto"obj".
--no-buildDon'tbuildtheproject.Onlyusethis
whenthebuildisup-to-date.
Script
>dotnetefmigrationsscript
Usage:dotnetefmigrationsscript[arguments][options]
Arguments:
Thestartingmigration.Defaultsto'0'(theinitialdatabase).
Theendingmigration.Defaultstothelastmigration.
Options:
-o|--outputThefiletowritetheresultto.
-i|--idempotentGenerateascriptthatcanbeusedona
databaseatanymigration.
-c|--contextTheDbContexttouse.
-p|--projectTheprojecttouse.
-s|--startup-projectThestartupprojecttouse.
--frameworkThetargetframework.
--configurationTheconfigurationtouse.
--runtimeTheruntimetouse.
--msbuildprojectextensionspathTheMSBuildprojectextensionspath.Defaultsto"obj".
--no-buildDon'tbuildtheproject.Onlyusethis
whenthebuildisup-to-date.
Previous
Home
FastestWaytoInsertusingEFExtensions
LearnC#,MVC,ASP.NETCore,LINQ,etc.