[英]Code-First Migrations and DataDirectory for LocalDb
It looks like the command "Update-Database" uses the Default Project's directory as the AppDomain instead of the Start-up Project's. 看起来命令“ Update-Database”使用默认项目的目录作为AppDomain而不是启动项目的目录。
I have a separate class library project that contains everything related to the database access, including the models and migrations, let's call it Project.Data . 我有一个单独的类库项目,其中包含与数据库访问有关的所有内容,包括模型和迁移,我们称之为Project.Data 。 One of the unit tests for this project requires me to run it on a LocalDb.
该项目的单元测试之一要求我在LocalDb上运行它。 So I created a connection string within the unit test's app.config.
因此,我在单元测试的app.config中创建了一个连接字符串。
Data Source=(LocalDb)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\MyDb.mdf;Initial Catalog=MyDb;Integrated Security=True
but the DataDirectory's value is null when I run the command "Update-Database". 但是当我运行命令“ Update-Database”时,DataDirectory的值为null。 And using the AppDomain's work directory is kinda unreliable here.
而且在这里使用AppDomain的工作目录有点不可靠。
How can I use the Unit Test's work directory when I run the "Update-Database" when the models and migrations-relate codes are in a separate class library? 当模型和迁移相关代码位于单独的类库中时,如何在运行“更新数据库”时使用单元测试的工作目录?
I think you have to you use the ProjectName
or StartUpProjectName
parameter when executing the update-database command. 我认为您必须在执行update-database命令时使用
ProjectName
或StartUpProjectName
参数。
See here for more details: update-database command reference 有关更多详细信息,请参见此处: update-database命令参考
Update-Database [-SourceMigration <String>] [-TargetMigration <String>] [-Script] [-Force]
[-ProjectName <String>] [-StartUpProjectName <String>] [-ConfigurationTypeName <String>]
-ConnectionString <String> -ConnectionProviderName <String>
[-AppDomainBaseDirectory <String>] [<CommonParameters>]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.