ef数据迁移命令总结之 Enable-Migrations
get-help Enable-Migration -detailed 在包管理控制台中可以查看详细信息。
摘要
Enables Code First Migrations in a project.
在项目中启用代码优先迁移。
语法
Enable-Migrations [-ContextTypeName <String>] [-EnableAutomaticMigrations] [-MigrationsDirectory <String>] [-ProjectName<String>] [-StartUpProjectName <String>] [-ContextProjectName <String>] [-ConnectionStringName <String>] [-Force] [-ContextAssemblyName <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>]
语法实例与讲解。
Enable-Migrations -ContextTypeName EmployeeDBContext #context类型-MigrationsDirectory CreateMigrations #自定义数据迁移文件夹-ProjectName 1-3EntityFrameWorkDemo #数据迁移类将被添加到哪个项目中-StartUpProjectName 1-3EntityFrameWorkDemo #数据库连接字符串配置文件 所在的项目-ContextProjectName 1-3EntityFrameWorkDemo context类所在项目-ConnectionStringName EmployeeDBContext 数据库连接字符串 名称 -Force 多次运行,是否重写迁移文件-Verbose 详细信息
说明
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).
通过在项目中搭建一个数据迁移配置类 来允许数据迁移。如果目标数据库 在初始化器中被创建,那么一个初始化迁移将会被创建。(排除自动迁移是通过EnableAutomaticMigrations参数启用的)
参数
-ContextTypeName <String>
Specifies the context to use. If omitted, migrations will attempt to locate a
single context type in the target project.
指定要使用的context类型。如果省略,migrations 将尝试定位目标项目中的单一的context类型。(不单一就报错了。。)
-EnableAutomaticMigrations [<SwitchParameter>]
Specifies whether automatic migrations will be enabled in the scaffolded migrations configuration.
If omitted, automatic migrations will be disabled.
指定在搭建的迁移配置中,自动迁移是否被允许。如果忽略,自动迁移被禁用。
-MigrationsDirectory <String>
Specifies the name of the directory that will contain migrations code files.
If omitted, the directory will be named “Migrations”.
指定存放迁移代码文件的文件目录,如果默认,将会指定Migrations文件夹。
-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.
指定搭建的迁移配置类 将被添加到哪个项目当中。如果忽略,将使用 包管理控制台中对的默认项目。
-StartUpProjectName <String>
Specifies the configuration file to use for named connection strings. If
omitted, the specified project’s configuration file is used.
指定 将要使用的 数据库连接字符串 的配置文件,如果忽略,将使用默认启动项目中的配置文件。
-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.
指定 DbContext 所在的项目名称,如果忽略,context 被认为与 migrations在一个项目 中。
-ConnectionStringName <String>
Specifies the name of a connection string to use from the application’s
configuration file.
确定应用配置文件中 的数据库连接字符串
-ConnectionString <String>
Specifies the connection string to use. If omitted, the context’s
default connection will be used.
指出数据库连接字符串,如果忽略,context的默认连接会被使用。
-ConnectionProviderName <String>
Specifies the provider invariant name of the connection string.
指出dataProvider,比如 providerName="System.Data.SqlClient
-Force [<SwitchParameter>]
Specifies that the migrations configuration be overwritten when running more
than once for a given project.
对给定的项目多次运行的时候,指定 migrations configuration 被重写。
-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.
指定包含DbContext 类的程序集名称,当 context 在一个被应用的程序集而不是一个项目的时候,用这个参数 替代ContextProjectName 。
-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.
指定app-domain的目录,从而迁移运行中可以代码生成,这样app-domain可以找到 所有需要的程序集。这是一个只有在解决方案包含多个项目时才需要的高级选项。从而 context和 configuration 所需要的程序集 ,并不需要全部被 包含context或者 包含migrations的项目引用。
————————————————
版权声明:本文为CSDN博主「一头小驴」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/qq_37326058/article/details/103990810
<CommonParameters>
此 Cmdlet 支持常见参数: Verbose、Debug、
ErrorAction、ErrorVariable、WarningAction、WarningVariable、
OutBuffer、PipelineVariable 和 OutVariable。有关详细信息,请参阅
about_CommonParameters (https:/go.microsoft.com/fwlink/?LinkID=113216)。
-------------------------- 示例 1 --------------------------PS C:\>Enable-Migrations# Scaffold a migrations configuration in a project with only one context-------------------------- 示例 2 --------------------------PS C:\>Enable-Migrations -Auto# Scaffold a migrations configuration with automatic migrations enabled for a project
# with only one context-------------------------- 示例 3 --------------------------PS C:\>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”.