2 entity-framework code-first ef-code-first ef-migrations
我正在使用代码优先迁移来为我的asp mvc站点创建和更新数据库.
我有一个DbContext,它位于解决方案的另一个项目中.
public class EFDbContext : DbContext
{
public DbSet<Book> Books { get; set; }
public DbSet<Author> Authors { get; set; }
public DbSet<Publisher> Publishers { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
当我启用迁移和添加迁移[名称]时.它似乎创建了自己的db
[foo-projectname].Domain.Concrete.EFDbContext
Run Code Online (Sandbox Code Playgroud)
而不是附加到我创建的数据库,称为[foo-projectname].在站点的webconfig中,连接字符串通过目录" [foo-projectname] " 引用.
如果我将webconfig更改为其他数据库,那么我将从已添加到该数据库的项目中获取结果.但是,我想使用我创建的数据库.
我不想坚持使用这个自动创建的原因是因为我不确定迁移到SqlServer并且不想再陷入困境.我也得到了错误
支持'EFDbContext'上下文的模型自...以来发生了变化
即使我没有改变任何东西.
X是包含派生DbContext类的项目名称.
Default project打开Package Manager Console是X.另一种解决方法是,在运行迁移语法时提供以下参数.
-ProjectName X -StartUpProjectName X
Run Code Online (Sandbox Code Playgroud)
一些参数说明:
-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.
-StartUpProjectName <String>
Specifies the configuration file to use for named connection strings. If
omitted, the specified project's configuration file is used.
-ConfigurationTypeName <String>
Specifies the migrations configuration to use. If omitted, migrations will
attempt to locate a single migrations configuration type in the target
project.
-ConnectionStringName <String>
Specifies the name of a connection string to use from the application's
configuration file.
-ConnectionString <String>
Specifies the the connection string to use. If omitted, the context's
default connection will be used.
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3194 次 |
| 最近记录: |