AddDbContext was called with configuration, but the context type 'MyDBContext' only declares a parameterless constructor
System.ArgumentException
HResult=0x80070057
Message=AddDbContext was called with configuration, but the context type 'MyDBContext' only declares a parameterless constructor.
This means that the configuration passed to AddDbContext will never be used.
If configuration is passed to AddDbContext, then 'MyDBContext' should declare a constructor that accepts a DbContextOptions<MyDBContext> and must pass it to the base constructor for DbContext.
Source=Microsoft.EntityFrameworkCore
StackTrace:
at Microsoft.Extensions.DependencyInjection.EntityFrameworkServiceCollectionExtensions.CheckContextConstructors[TContext]()
at Microsoft.Extensions.DependencyInjection.EntityFrameworkServiceCollectionExtensions.AddDbContext[TContextService,TContextImplementation](IServiceCollection serviceCollection, Action` optionsAction, ServiceLifetime contextLifetime, ServiceLifetime optionsLifetime)
at Microsoft.Extensions.DependencyInjection.EntityFrameworkServiceCollectionExtensions.AddDbContext[TContextService,TContextImplementation](IServiceCollection serviceCollection, Action` optionsAction, ServiceLifetime contextLifetime, ServiceLifetime optionsLifetime)
at Microsoft.Extensions.DependencyInjection.EntityFrameworkServiceCollectionExtensions.AddDbContext[TContext](IServiceCollection serviceCollection, Action` optionsAction, ServiceLifetime contextLifetime, ServiceLifetime optionsLifetime)
at WebApi1.Startup.ConfigureServices(IServiceCollection services) in C:\Users\pxm\source\repos\WebApi1\WebApi1\Startup.cs:line
at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor, Boolean wrapExceptions)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at Microsoft.AspNetCore.Hosting.ConfigureServicesBuilder.InvokeCore(Object instance, IServiceCollection services)
at Microsoft.AspNetCore.Hosting.ConfigureServicesBuilder.<>c__DisplayClass9_0.<Invoke>g__Startup|(IServiceCollection serviceCollection)
at Microsoft.AspNetCore.Hosting.ConfigureServicesBuilder.Invoke(Object instance, IServiceCollection services)
at Microsoft.AspNetCore.Hosting.ConfigureServicesBuilder.<>c__DisplayClass8_0.<Build>b__0(IServiceCollection services)
at Microsoft.AspNetCore.Hosting.GenericWebHostBuilder.UseStartup(Type startupType, HostBuilderContext context, IServiceCollection services)
at Microsoft.AspNetCore.Hosting.GenericWebHostBuilder.<>c__DisplayClass12_0.<UseStartup>b__0(HostBuilderContext context, IServiceCollection services)
at Microsoft.Extensions.Hosting.HostBuilder.CreateServiceProvider()
at Microsoft.Extensions.Hosting.HostBuilder.Build()
at WebApi1.Program.Main(String[] args) in C:\Users\pxm\source\repos\WebApi1\WebApi1\Program.cs:line
翻译:
已使用配置调用AddDbContext,但上下文类型“MyDBContext”仅声明一个无参数构造函数。这意味着传递给AddDbContext的配置将永远不会被使用。
如果将配置传递给AddDbContext,那么“MyDBContext”应该声明一个接受DbContextOptions<MyDBContext>的构造函数,并且必须将其传递给DbContext的基本构造函数。
解决方法:
MyDBContext添加一个DbContextOptions<MyDBContext>类型参数的构造函数
AddDbContext was called with configuration, but the context type 'MyDBContext' only declares a parameterless constructor的更多相关文章
- AddDbContext was called with configuration, but the context type 'NewsContext' only declares a parameterless constructor?
问题 An error occurred while starting the application. ArgumentException: AddDbContext was called with ...
- Code First 启用迁移时出错 "No context type was found in the assembly"
问题:Code First 启用迁移时找不到上下文DbContext所在的项目. PM> Enable-Migrations No context type was found in the a ...
- VS EF Error: Configuration Error extension=".edmx" type="System.Data.Entity.Design.AspNet.EntityDesignerBuildProvider"
错误截图: Configuration Error :<add extension=".edmx" type="System.Data.Entity.Design. ...
- EntityFramework 启用迁移 Enable-Migrations 报异常 "No context type was found in the assembly"
转自:http://www.cnblogs.com/stevenhqq/archive/2013/04/18/3028350.html 以前做项目的时候,没有采用分类库的形式,所以迁移一致非常顺利,没 ...
- EntityFramework codefirst Enable-Migrations No context type was found in the assembly “MyApp.Web” error
Enable-Migrations -Force -ContextTypeName "MyApp.Repository.DataContext" -ProjectName &quo ...
- No context type was found in the assembly
如果解决方法中有多个项目存在,记住要在默认项目中选择你需要的项目进行 enable-migrations add-migration 以及updatebase
- 关于C#你应该知道的2000件事
原文 关于C#你应该知道的2000件事 下面列出了迄今为止你应该了解的关于C#博客的2000件事的所有帖子. 帖子总数= 1,219 大会 #11 -检查IL使用程序Ildasm.exe d #179 ...
- Android应用程序窗口(Activity)的运行上下文环境(Context)的创建过程分析
文章转载至CSDN社区罗升阳的安卓之旅,原文地址:http://blog.csdn.net/luoshengyang/article/details/8201936 在前文中,我们简要介绍了Andro ...
- The logback manual #03# Configuration
索引 Configuration in logback Automatically configuring logback Automatic configuration with logback-t ...
随机推荐
- 2018-06-18 sublime代码编辑器
sublime代码编辑器:主流前端开发编辑器,体积较小,运行速度快,文本功能强大,支持VI扩展,linux下面有个自带的文本编辑神器,名字叫做:vi ,熟练vi模式可以大量减少使用鼠标的次数,从而增加 ...
- 3、get请求(url详解)
前言 上一篇介绍了Composer的功能,可以模拟get和post请求,get请求有些是不带参数的,这种比较容易,直接放到url地址栏就行.有些get请求会带有参数,本篇详细介绍url地址格式. 一. ...
- Nodejs模块介绍
1.模块系统 require:引入模块,返回一个对象 module:指代当前的模块对象 module.exports:当前模块的导出对象 exports:指代module.exports __file ...
- oracle的操作-表空间
查询以创建的表空间 select dbms_metadata.get_ddl('TABLESPACE','你的表空间名称') from dual; --查询空间创建的位置 select t1.name ...
- xampp-apache配置
我安装的软件是xampp-win32-1.8.2-0-VC9-installer 需要配置的文件有 httpd.conf httpd-default.conf httpd-info.conf http ...
- IE8/IE9/IE10打开网页后,自动设置浏览器模式为“IE8/IE9/IE10兼容性视图”
http://blog.snsgou.com/post-16.html 作者:SNSGOU 发布于:2013-07-17 22:23:05 分类:CSS/HTML 评论(0) 浏览(132 ...
- Maven、Gradle 配置国内镜像源
Maven 全局配置 修改 Maven 默认的全局配置文件: 类 Unix 系统: Mac OS / Linux 默认在 ~/.m2/settings.xml Windows 系统:一般在 Maven ...
- Mysql-NULL转数字
最近做了一个学生成绩表,其中遇到一个小问题 需要统计个门科目的平均成绩,在统计到高等数学时,因为高数没有人考,在成绩表中根本不存在的分数,但是在课程表存在高数科目. 当这两个表内联然后统计分数,这样会 ...
- springboot restful接口 如何接受前端的PUT和DELETE请求
最近项目组有人问我,"springboot怎么接受不到前端提交的PUT和DELETE请求?" 于是有了这篇文章,本篇文章主要解决两个问题: js好像只能提交GET.POST请求耶? ...
- vue-cli3的eslint配置问题
vue-cli3按照官网教程配置搭建后,发现每次编译,eslint都抛出错误 error: Expected indentation of 4 spaces but found 0 (indent) ...