我使用的是Code-First,使用标准模板创建网站,然后继续向main添加表applicationDBContext,但是现在当我在Package Manager控制台中启用Enable-Migrations时,
在程序集“ DOC”中找不到上下文类型。
当我把完整的路径使用:
ContextTypeName Option enable-migrations -ContextTypeName DOC.Migrations.Configuration
Run Code Online (Sandbox Code Playgroud)
...我得到:
已经在项目“ DOC”中启用了迁移。要覆盖现有的迁移配置,请使用-Force参数。
当我去-Force时,它说
为项目DOC启用了代码优先迁移。
但是当我尝试添加迁移时,我得到了
错误CS0311类型'DOC.Migrations.Configuration'不能用作通用类型或方法'DbMigrationsConfiguration'中的类型参数'TContext'。没有从“ DOC.Migrations.Configuration”到“ System.Data.Entity.DbContext”的隐式引用转换。DOC xxxxxxx \ DOC \ Migrations \ Configuration.cs。
当我检查Configuration.cs文件时,将其更改为:
internal sealed class Configuration : DbMigrationsConfiguration
Run Code Online (Sandbox Code Playgroud)
...至:
internal sealed class Configuration : DbMigrationsConfiguration
Run Code Online (Sandbox Code Playgroud)
...导致项目无法建立
我唯一设法通过将实体框架从6.1.3降级到6.1.2,然后重新升级来使此工作正常进行。
有时,我必须升级和降级几次,关闭VS并重新打开,然后它才能工作。
这个问题有方法解决吗?它很烦人。
我还注意到我的DbContext课程来自IdentityDBContext,可以吗?我知道通常您是从派生它的DbContext,但是由于我是使用向导启动该项目的,因此它会自动创建它,而我只是将其他表添加到其中。
我的web.config
<?xml version="1.0" encoding="utf-8"?>
<!--
For more information on how to configure your ASP.NET application, …Run Code Online (Sandbox Code Playgroud)