Package Manager Console Commands

文章推薦指數: 80 %
投票人數:10人

The Package Manager Console is available within Visual Studio by going to Tools » Nuget ... Update-Database Updates the database to a specified migration. Togglenavigation LearnEntityFrameworkCore YourguidetousingthelatestversionofMicrosoft'sObjectRelationalMapper  EFCoreNewsletter Home HowToGetEFCore DbContext AddingData ModifyingData DeletingData ChangeTracker DbSet QueryingData AddingData ModifyingData DeletingData Model FromExistingDatabase ShadowProperties Relationships ManagingOneToManyRelationships ReferentialConstraintActionOptions Conventions OneToManyRelationship OneToOneRelationship ManyToManyRelationship Configuration DataAnnotationAttributes ColumnAttribute ComplexTypeAttribute ConcurrencyCheckAttribute DatabaseGeneratedAttribute ForeignKeyAttribute IndexAttribute InversePropertyAttribute KeyAttribute MaxLengthAttribute NotMappedAttribute RequiredAttribute StringLengthAttribute TableAttribute TimestampAttribute FluentApi ModelConfiguration PropertyConfiguration HasAlternatekeyMethod HasColumnNameMethod HasColumnTypeMethod HasComputedColumnSqlMethod HasConstraintNameMethod HasDataMethod HasDefaultValueMethod HasDefaultValueSqlMethod HasDiscriminatorMethod HasFieldMethod HasForeignKeyMethod HasIndexMethod HasKeyMethod HasManyMethod HasMaxLengthMethod HasOneMethod HasQueryFilterMethod HasValueMethod Has/WithPattern IgnoreMethod IsConcurrencyTokenMethod IsRequiredMethod IsRowVersionMethod OnDeleteMethod ToTableMethod ToViewMethod TypeConfiguration ValueGeneratedNeverMethod ValueGeneratedOnAddMethod ValueGeneratedOnAddOrUpdateMethod WithManyMethod WithOneMethod OneToManyRelationshipConfiguration OneToOneRelationshipConfiguration ManyToManyRelationshipConfiguration ConnectionStrings Inheritance TablePerHierarchy Concurrency Migrations ModelSnapshot SeedingData Commands CLICommands PMCCommands Walkthoughs ASP.NETCoreMVCApplication .NETCoreConsoleApplication UsingAnExistingDatabase RawSQL DatabaseFirstAndEntityFrameworkCore QueryTypes LazyLoading FastestEntityFrameworkExtensions BulkInsert BulkDelete BulkUpdate BulkMerge PackageManagerConsoleCommands ThePackageManagerConsoleisavailablewithinVisualStudiobygoingtoTools»NugetPackageManager. IfyouwanttousethePackageManagerConsoletoexecutemigrationscommand,youneedtoensurethatthelatestversionofMicrosoft.EntityFrameworkCore.Toolsisaddedtoyourproject.jsonfile. ThecommandsthatyouexecutetomanagemigrationsfromthePackageManagerConsolearelargelythesameasthoseforEntityFramework6.Thefullrangeofcommandscanbefoundbytypingget-helpentityframeworkatthePMprompt: PM>get-helpentityframework _/\__ ---==/\\ ______|.\|\ |__||__||)\\\ |_||_|\_/|//|\\ |___||_|/\\\/\\ TOPIC about_EntityFramework SHORTDESCRIPTION ProvidesinformationaboutEntityFrameworkcommands. LONGDESCRIPTION ThistopicdescribestheEntityFrameworkcommands.EntityFrameworkisMicrosoft'srecommendeddataaccesstechnologyfornew applications. ThefollowingEntityFrameworkcmdletsareincluded. CmdletDescription ----------------------------------------------------------------------------- Add-Migration Addsanewmigration. Remove-Migration Removesthelastmigration. Scaffold-DbContext ScaffoldsaDbContextandentitytypeclassesforaspecifieddatabase. Script-Migration GeneratesaSQLscriptfrommigrations. Update-Database Updatesthedatabasetoaspecifiedmigration. Use-DbContextSetsthedefaultDbContexttouse. SEEALSO Add-Migration Remove-Migration Scaffold-DbContext Script-Migration Update-Database Use-DbContext Youcangetfurtherhelpforspecificcommandsbytypingget-helpfollowedbythecommandname.Forexample,thefollowingoutputisgeneratedasaresultoftypingget-helpadd-migration: Add-migration NAME Add-Migration SYNOPSIS Addsanewmigration. SYNTAX Add-Migration[-Name][-OutputDir][-Context][-Project][-StartupProject][-Environment][] DESCRIPTION Addsanewmigration. Notes ThemigrationfileswillbeplacedinafoldernameMigrationsbydefault.Thiswillbecreatedintherootoftheprojectunlessanalternativelocationisspecifiedusingthe-outputdirswitch.Ifyouspecifyanalternativelocationwithoutputdir,thevaluewillberootedintheprojectdirectory.Itshouldnotbeprefixedwithapathseparator(e.g.'/'). Remove-Migration NAME Remove-Migration SYNOPSIS Removesthelastmigration. SYNTAX Remove-Migration[-Force][-Context][-Environment][-Project][-StartupProject][] DESCRIPTION Removesthelastmigration. RELATEDLINKS Add-Migration about_EntityFrameworkCore REMARKS Toseetheexamples,type:"get-helpRemove-Migration-examples". Formoreinformation,type:"get-helpRemove-Migration-detailed". Fortechnicalinformation,type:"get-helpRemove-Migration-full". Scaffold-DbContext NAME Scaffold-DbContext SYNOPSIS ScaffoldsaDbContextandentitytypesforadatabase. SYNTAX Scaffold-DbContext[-Connection][-Provider][-OutputDir][-Context][-Schemas][-Tables][-DataAnnotations][-Force][-Environment][-Project] [-StartupProject][] DESCRIPTION ScaffoldsaDbContextandentitytypesforadatabase. RELATEDLINKS about_EntityFrameworkCore REMARKS Toseetheexamples,type:"get-helpScaffold-DbContext-examples". Formoreinformation,type:"get-helpScaffold-DbContext-detailed". Fortechnicalinformation,type:"get-helpScaffold-DbContext-full". Script-Migration NAME Script-Migration SYNOPSIS GeneratesaSQLscriptfrommigrations. SYNTAX Script-Migration[-From][-To][-Idempotent][-Context][-Environment][-Project][-StartupProject][] Script-Migration[[-From]][-Idempotent][-Context][-Environment][-Project][-StartupProject][] DESCRIPTION GeneratesaSQLscriptfrommigrations. RELATEDLINKS Update-Database about_EntityFrameworkCore REMARKS Toseetheexamples,type:"get-helpScript-Migration-examples". Formoreinformation,type:"get-helpScript-Migration-detailed". Fortechnicalinformation,type:"get-helpScript-Migration-full". Notes Thescript-migrationcommandwillscriptallmigrations,regardlesswhethertheyhavebeenappliedornot.Ifyouonlywanttoscriptthemostrecentmigration,thevaluetoapplytothe-fromswitchisthelastmigrationthatwasapplied.Youcanread-fromasmeaning"after",not"including". Update-Database NAME Update-Database SYNOPSIS Updatesthedatabasetoaspecifiedmigration. SYNTAX Update-Database[[-Migration]][-Context][-Environment][-Project][-StartupProject][] DESCRIPTION Updatesthedatabasetoaspecifiedmigration. RELATEDLINKS Script-Migration about_EntityFrameworkCore REMARKS Toseetheexamples,type:"get-helpUpdate-Database-examples". Formoreinformation,type:"get-helpUpdate-Database-detailed". Fortechnicalinformation,type:"get-helpUpdate-Database-full". Onthispage PackageManagerConsoleCommands Add-migration Remove-Migration Scaffold-DbContext Script-Migration Update-Database LatestUpdates PackageManagerConsoleCommands CommandLineInterfacecommands CommandsinEntityFrameworkCore TheFluentAPIWithOneMethod TheFluentAPIWithManyMethod TheFluentAPIValueGeneratedOnAddOrUpdateMethod



請為這篇文章評分?