标签:
名称 |
Enable-Migrations
|
摘要 |
Enables Code First Migrations in a project.
|
语法 |
Enable-Migrations [-ContextTypeName <String>] [-EnableAutomaticMigrations] [-MigrationsDirectory <String>] [-ProjectName <String>] [-StartUpProjectName <String>] [-ContextProjectName <String>] [-ConnectionStringName <String>] [-Force] [-ContextA
ssemblyName <String>] [-AppDomainBaseDirectory <String>] [<CommonParameters>] Enable-Migrations [-ContextTypeName <String>] [-EnableAutomaticMigrations] [-MigrationsDirectory <String>] [-ProjectName <String>] [-StartUpProjectName <String>] [-ContextProjectName <String>] -ConnectionString <String> -ConnectionProviderName < String> [-Force] [-ContextAssemblyName <String>] [-AppDomainBaseDirectory <String>] [<CommonParameters>] |
说明 |
Enables Migrations by scaffolding a migrations configuration class in the project. If the
target database was created by an initializer, an initial migration will be created (unless automatic migrations are enabled via the EnableAutomaticMigrations parameter). |
参数 |
-ContextTypeName <String>
Specifies the context to use. If omitted, migrations will attempt to locate a single context type in the target project. 是否必需? False 位置? named 默认值 是否接受管道输入? false 是否接受通配符? False -EnableAutomaticMigrations [<SwitchParameter>] Specifies whether automatic migrations will be enabled in the scaffolded migrations configuration. If omitted, automatic migrations will be disabled. 是否必需? False 位置? named 默认值 False 是否接受管道输入? false 是否接受通配符? False -MigrationsDirectory <String> Specifies the name of the directory that will contain migrations code files. If omitted, the directory will be named "Migrations". 是否必需? False 位置? named 默认值 是否接受管道输入? false 是否接受通配符? False -ProjectName <String> Specifies the project that the scaffolded migrations configuration class will be added to. If omitted, the default project selected in package manager console is used. 是否必需? False 位置? named 默认值 是否接受管道输入? false 是否接受通配符? False -StartUpProjectName <String> Specifies the configuration file to use for named connection strings. If omitted, the specified project‘s configuration file is used. 是否必需? False 位置? named 默认值 是否接受管道输入? false 是否接受通配符? False -ContextProjectName <String> Specifies the project which contains the DbContext class to use. If omitted, the context is assumed to be in the same project used for migrations. 是否必需? False 位置? named 默认值 是否接受管道输入? false 是否接受通配符? False -ConnectionStringName <String> Specifies the name of a connection string to use from the application‘s configuration file. 是否必需? False 位置? named 默认值 是否接受管道输入? false 是否接受通配符? False -ConnectionString <String> Specifies the the connection string to use. If omitted, the context‘s default connection will be used. 是否必需? True 位置? named 默认值 是否接受管道输入? false 是否接受通配符? False -ConnectionProviderName <String> Specifies the provider invariant name of the connection string. 是否必需? True 位置? named 默认值 是否接受管道输入? false 是否接受通配符? False -Force [<SwitchParameter>] Specifies that the migrations configuration be overwritten when running more than once for a given project. 是否必需? False 位置? named 默认值 False 是否接受管道输入? false 是否接受通配符? False -ContextAssemblyName <String> Specifies the name of the assembly which contains the DbContext class to use. Use this parameter instead of ContextProjectName when the context is contained in a referenced assembly rather than in a project of the solution. 是否必需? False 位置? named 默认值 是否接受管道输入? false 是否接受通配符? False -AppDomainBaseDirectory <String> Specifies the directory to use for the app-domain that is used for running Migrations code such that the app-domain is able to find all required assemblies. This is an advanced option that should only be needed if the solution contains several projects such that the assemblies needed for the context and configuration are not all referenced from either the project containing the context or the project containing the migrations. 是否必需? False 位置? named 默认值 是否接受管道输入? false 是否接受通配符? False <CommonParameters> 此 Cmdlet 支持常见参数: Verbose、Debug、 ErrorAction、ErrorVariable、WarningAction、WarningVariable、 OutBuffer、PipelineVariable 和 OutVariable。有关详细信息,请参阅 about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216)。 |
示例 1 |
C:\PS>Enable-Migrations
# Scaffold a migrations configuration in a project with only one context |
示例 2 |
C:\PS>Enable-Migrations -Auto
# Scaffold a migrations configuration with automatic migrations enabled for a project # with only one context |
示例 3 |
C:\PS>Enable-Migrations -ContextTypeName MyContext -MigrationsDirectory DirectoryName
# Scaffold a migrations configuration for a project with multiple contexts # This scaffolds a migrations configuration for MyContext and will put the configuration # and subsequent configurations in a new directory called "DirectoryName" |
备注 |
备注 若要查看示例,请键入: "get-help Enable-Migrations -examples". 有关详细信息,请键入: "get-help Enable-Migrations -detailed". 若要获取技术信息,请键入: "get-help Enable-Migrations -full". |
名称 |
Add-Migration
|
摘要 |
Scaffolds a migration script for any pending model changes.
|
语法 |
Add-Migration [-Name] <String> [-Force] [-ProjectName <String>] [-StartUpProjectName <String>] [-ConfigurationTypeName <String>] [-ConnectionStringName <String>] [-IgnoreChanges] [-AppDomainBaseDirectory <String>] [<CommonParameters>]
Add-Migration [-Name] <String> [-Force] [-ProjectName <String>] [-StartUpProjectName <String>] [-ConfigurationTypeName <String>] -ConnectionString <String> -ConnectionProviderName <String> [-IgnoreChanges] [-AppDomainBaseDirectory <String>] [<CommonParamet ers>] |
说明 |
Scaffolds a new migration script and adds it to the project.
|
参数 |
-Name <String> Specifies the name of the custom script. 是否必需? True 位置? 1 默认值 是否接受管道输入? false 是否接受通配符? False -Force [<SwitchParameter>] Specifies that the migration user code be overwritten when re-scaffolding an existing migration. 是否必需? False 位置? named 默认值 False 是否接受管道输入? false 是否接受通配符? False -ProjectName <String> Specifies the project that contains the migration configuration type to be used. If omitted, the default project selected in package manager console is used. 是否必需? False 位置? named 默认值 是否接受管道输入? false 是否接受通配符? False -StartUpProjectName <String> Specifies the configuration file to use for named connection strings. If omitted, the specified project‘s configuration file is used. 是否必需? False 位置? named 默认值 是否接受管道输入? false 是否接受通配符? False -ConfigurationTypeName <String> Specifies the migrations configuration to use. If omitted, migrations will attempt to locate a single migrations configuration type in the target project. 是否必需? False 位置? named 默认值 是否接受管道输入? false 是否接受通配符? False -ConnectionStringName <String> Specifies the name of a connection string to use from the application‘s configuration file. 是否必需? False 位置? named 默认值 是否接受管道输入? false 是否接受通配符? False -ConnectionString <String> Specifies the the connection string to use. If omitted, the context‘s default connection will be used. 是否必需? True 位置? named 默认值 是否接受管道输入? false 是否接受通配符? False -ConnectionProviderName <String> Specifies the provider invariant name of the connection string. 是否必需? True 位置? named 默认值 是否接受管道输入? false 是否接受通配符? False -IgnoreChanges [<SwitchParameter>] Scaffolds an empty migration ignoring any pending changes detected in the current model. This can be used to create an initial, empty migration to enable Migrations for an existing database. N.B. Doing this assumes that the target database schema is compatible with the current model. 是否必需? False 位置? named 默认值 False 是否接受管道输入? false 是否接受通配符? False -AppDomainBaseDirectory <String> Specifies the directory to use for the app-domain that is used for running Migrations code such that the app-domain is able to find all required assemblies. This is an advanced option that should only be needed if the solution contains several projects such that the assemblies needed for the context and configuration are not all referenced from either the project containing the context or the project containing the migrations. 是否必需? False 位置? named 默认值 是否接受管道输入? false 是否接受通配符? False <CommonParameters> 此 Cmdlet 支持常见参数: Verbose、Debug、 ErrorAction、ErrorVariable、WarningAction、WarningVariable、 OutBuffer、PipelineVariable 和 OutVariable。有关详细信息,请参阅 about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216)。 |
示例 1 |
C:\PS>Add-Migration First
# Scaffold a new migration named "First"
|
示例 2 |
C:\PS>Add-Migration First -IgnoreChanges
# Scaffold an empty migration ignoring any pending changes detected in the current model.
# This can be used to create an initial, empty migration to enable Migrations for an existing
# database. N.B. Doing this assumes that the target database schema is compatible with the
# current model.
|
示例 3 |
|
备注 |
若要查看示例,请键入: "get-help Add-Migration -examples".
有关详细信息,请键入: "get-help Add-Migration -detailed".
若要获取技术信息,请键入: "get-help Add-Migration -full".
|
名称 |
Update-Database
|
摘要 |
Applies any pending migrations to the database.
|
语法 |
Update-Database [-SourceMigration <String>] [-TargetMigration <String>] [-Script] [-Force] [-ProjectName <String>] [-StartUpProjectName <String>] [-ConfigurationTypeName <String>] [-ConnectionStringName <String>] [-AppDomainBaseDirectory <String>] [<Common
Parameters>]
Update-Database [-SourceMigration <String>] [-TargetMigration <String>] [-Script] [-Force] [-ProjectName <String>] [-StartUpProjectName <String>] [-ConfigurationTypeName <String>] -ConnectionString <String> -ConnectionProviderName <String> [-AppDomainBaseD
irectory <String>] [<CommonParameters>]
|
说明 |
Updates the database to the current model by applying pending migrations.
|
参数 |
-SourceMigration <String> Only valid with -Script. Specifies the name of a particular migration to use as the update‘s starting point. If omitted, the last applied migration in the database will be used. 是否必需? False 位置? named 默认值 是否接受管道输入? false 是否接受通配符? False -TargetMigration <String> Specifies the name of a particular migration to update the database to. If omitted, the current model will be used. 是否必需? False 位置? named 默认值 是否接受管道输入? false 是否接受通配符? False -Script [<SwitchParameter>] Generate a SQL script rather than executing the pending changes directly. 是否必需? False 位置? named 默认值 False 是否接受管道输入? false 是否接受通配符? False -Force [<SwitchParameter>] Specifies that data loss is acceptable during automatic migration of the database. 是否必需? False 位置? named 默认值 False 是否接受管道输入? false 是否接受通配符? False -ProjectName <String> Specifies the project that contains the migration configuration type to be used. If omitted, the default project selected in package manager console is used. 是否必需? False 位置? named 默认值 是否接受管道输入? false 是否接受通配符? False -StartUpProjectName <String> Specifies the configuration file to use for named connection strings. If omitted, the specified project‘s configuration file is used. 是否必需? False 位置? named 默认值 是否接受管道输入? false 是否接受通配符? False -ConfigurationTypeName <String> Specifies the migrations configuration to use. If omitted, migrations will attempt to locate a single migrations configuration type in the target project. 是否必需? False 位置? named 默认值 是否接受管道输入? false 是否接受通配符? False -ConnectionStringName <String> Specifies the name of a connection string to use from the application‘s configuration file. 是否必需? False 位置? named 默认值 是否接受管道输入? false 是否接受通配符? False -ConnectionString <String> Specifies the the connection string to use. If omitted, the context‘s default connection will be used. 是否必需? True 位置? named 默认值 是否接受管道输入? false 是否接受通配符? False -ConnectionProviderName <String> Specifies the provider invariant name of the connection string. 是否必需? True 位置? named 默认值 是否接受管道输入? false 是否接受通配符? False -AppDomainBaseDirectory <String> Specifies the directory to use for the app-domain that is used for running Migrations code such that the app-domain is able to find all required assemblies. This is an advanced option that should only be needed if the solution contains several projects such that the assemblies needed for the context and configuration are not all referenced from either the project containing the context or the project containing the migrations. 是否必需? False 位置? named 默认值 是否接受管道输入? false 是否接受通配符? False <CommonParameters> 此 Cmdlet 支持常见参数: Verbose、Debug、 ErrorAction、ErrorVariable、WarningAction、WarningVariable、 OutBuffer、PipelineVariable 和 OutVariable。有关详细信息,请参阅 about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216)。 |
示例 1 |
C:\PS>Update-Database
# Update the database to the latest migration
|
示例 2 |
C:\PS>Update-Database -TargetMigration Second
# Update database to a migration named "Second"
# This will apply migrations if the target hasn‘t been applied or roll back migrations
# if it has
|
示例 3 |
C:\PS>Update-Database -Script
# Generate a script to update the database from it‘s current state to the latest migration
|
示例4 |
C:\PS>Update-Database -Script -SourceMigration Second -TargetMigration First
# Generate a script to migrate the database from a specified start migration
# named "Second" to a specified target migration named "First"
|
示例5 |
C:\PS>Update-Database -Script -SourceMigration $InitialDatabase
# Generate a script that can upgrade a database currently at any version to the latest version.
# The generated script includes logic to check the __MigrationsHistory table and only apply changes
# that haven‘t been previously applied.
|
示例6 |
C:\PS>Update-Database -TargetMigration $InitialDatabase
# Runs the Down method to roll-back any migrations that have been applied to the database
|
备注 |
若要查看示例,请键入: "get-help Update-Database -examples".
有关详细信息,请键入: "get-help Update-Database -detailed".
若要获取技术信息,请键入: "get-help Update-Database -full".
|
名称 |
Get-Migrations
|
摘要 |
Displays the migrations that have been applied to the target database.
|
语法 |
Get-Migrations [-ProjectName <String>] [-StartUpProjectName <String>] [-ConfigurationTypeName <String>] [-ConnectionStringName <String>] [-AppDomainBaseDirectory <String>] [<CommonParameters>]
Get-Migrations [-ProjectName <String>] [-StartUpProjectName <String>] [-ConfigurationTypeName <String>] -ConnectionString <String> -ConnectionProviderName <String> [-AppDomainBaseDirectory <String>] [<CommonParameters>]
|
说明 |
Displays the migrations that have been applied to the target database.
|
参数 |
-ProjectName <String>
Specifies the project that contains the migration configuration type to be used. If omitted, the default project selected in package manager console is used. 是否必需? False 位置? named 默认值 是否接受管道输入? false 是否接受通配符? False -StartUpProjectName <String> Specifies the configuration file to use for named connection strings. If omitted, the specified project‘s configuration file is used. 是否必需? False 位置? named 默认值 是否接受管道输入? false 是否接受通配符? False -ConfigurationTypeName <String> Specifies the migrations configuration to use. If omitted, migrations will attempt to locate a single migrations configuration type in the target project. 是否必需? False 位置? named 默认值 是否接受管道输入? false 是否接受通配符? False -ConnectionStringName <String> Specifies the name of a connection string to use from the application‘s configuration file. 是否必需? False 位置? named 默认值 是否接受管道输入? false 是否接受通配符? False -ConnectionString <String> Specifies the the connection string to use. If omitted, the context‘s default connection will be used. 是否必需? True 位置? named 默认值 是否接受管道输入? false 是否接受通配符? False -ConnectionProviderName <String> Specifies the provider invariant name of the connection string. 是否必需? True 位置? named 默认值 是否接受管道输入? false 是否接受通配符? False -AppDomainBaseDirectory <String> Specifies the directory to use for the app-domain that is used for running Migrations code such that the app-domain is able to find all required assemblies. This is an advanced option that should only be needed if the solution contains several projects such that the assemblies needed for the context and configuration are not all referenced from either the project containing the context or the project containing the migrations. 是否必需? False 位置? named 默认值 是否接受管道输入? false 是否接受通配符? False <CommonParameters> 此 Cmdlet 支持常见参数: Verbose、Debug、 ErrorAction、ErrorVariable、WarningAction、WarningVariable、 OutBuffer、PipelineVariable 和 OutVariable。有关详细信息,请参阅 about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216)。 |
示例 1 |
|
示例 2 |
|
示例 3 |
|
备注 |
若要查看示例,请键入: "get-help Get-Migrations -examples".
有关详细信息,请键入: "get-help Get-Migrations -detailed".
若要获取技术信息,请键入: "get-help Get-Migrations -full".
|
标签:
原文地址:http://www.cnblogs.com/zeusro/p/4241934.html