zoukankan      html  css  js  c++  java
  • No context type was found in the assembly 'xxx.xxxx'. CodeFirst Ef错误

    最简单的解决方案是将启动项目设置为你要生产Migration的项目。

    例如:

    我这边将Try.EntityFramework设置为启动项目。并且准备在该项目下生成Migration文件。这里的默认项目同样设置为Try.EntityFramework。就OK了。

    2.另一种方案。

    查看get-help Enable-Migrations帮助,发现启用迁移命令带了几个参数。

    Enable-Migrations [-ContextTypeName <String>] [-EnableAutomaticMigrations] [-ProjectName <String>] [-StartUpProjectName <String>] [-ConnectionStringName <String>] [-Force] [<CommonParameters>]

    ContextTypeName:项目继承自DBContext的类名字。

    EnableAutomaticMigrations:开启自动迁移。

    ProjectName:存放DBContext类的项目名称。

    StartUpProjectName:解决方案中启动项目的名称,作用是调用该项目下的连接字符串。

    ConnectionStringName:连接字符串名称

    上面五个参数是解决问题必须的,其它的无关紧要。

    例如:

    Enable-Migrations -ContextTypeName "Try.EntityFramework.TryDbContext" -ProjectName "Try.EntityFramework" -StartUpProjectName "Try.EntityFramework" -ConnectionStringName "Default" -Verbose

    依次填好之后,问题解决。

    同样的在Add-Migration、Update-Database的时候也需要填写相应的参数。否则会出现同样错误。

    例如:

    add-migration -Name "InitDb" -ProjectName "Try.EntityFramework" -StartUpProjectName "Try.EntityFramework" -ConnectionStringName "Default" -Verbose

    update-database -script -ProjectName "Try.EntityFramework" -StartUpProjectName "Try.EntityFramework" -ConnectionStringName "Default" -Verbose

  • 相关阅读:
    圆形刻度盘 进度 展示
    弧度、角度换算公式
    placeholder 颜色更改
    移除HTML5 input在type="number"时的上下小箭头
    linux 安装python-setuptools
    通过helm 安装 harbor 不成功问题处理
    k8s 添加ingress 暴露服务
    k8s编辑pod配置信息
    postgres 数据导入导出
    万能视频后台转码
  • 原文地址:https://www.cnblogs.com/FlyStupidBird/p/8944782.html
Copyright © 2011-2022 走看看