您现在的位置是:网站首页> 编程资料编程资料
VS2017添加EF的MVC控制器报错的解决方法_实用技巧_
2023-05-24
261人已围观
简介 VS2017添加EF的MVC控制器报错的解决方法_实用技巧_
VS2017添加EF的MVC控制器报错的解决方法,供大家参考,具体内容如下
1. 错误描述:no database provider has been configured fot this DbContext.
此类错误是上下文的注册造成的.解决方式在DBContext中重写OnConfiguring方法去注入数据库连接.
DbContext中:
public static string ConnectionString { get; set; } protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) { optionsBuilder.UseSqlServer(ConnectionString); base.OnConfiguring(optionsBuilder); }在Startup.cs中
public void ConfigureServices(IServiceCollection services) { // Add framework services. var sqlserverConnection = Configuration.GetConnectionString("SQLServerConnection"); DbContext.ConnectionString = sqlserverConnection;//将配置连接传入DbContext中 services.AddDbContext(options => options.UseSqlServer(sqlserverConnection)); services.AddMvc(); } 2.错误描述:Could not add Model type XXX to DbContext
错误描述没有注册DbSet属性.但实际上是有 public DbSet
更多精彩内容大家可以点击《Visual Studio 2017开发使用教程》,关于visual studio的安装教程可以点击《Visual Studio安装使用手册》进行学习,希望大家喜欢。
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。
您可能感兴趣的文章:
相关内容
- ASP.NET Core部署前期准备 使用Hyper-V安装Ubuntu Server 16.10_实用技巧_
- VS2017 Cordova Ionic2 移动开发环境搭建教程_实用技巧_
- ASP.NET MVC 4 中的JSON数据交互的方法_实用技巧_
- WPF下YUV播放的D3D解决方案_实用技巧_
- 解决WPF中空域问题(Airspace issuse)_实用技巧_
- WPF中在摄像头视频上叠加控件的解决方案_实用技巧_
- ASP.NET Core应用中与第三方IoC/DI框架的整合_实用技巧_
- .NetCore实现上传多文件的示例详解_实用技巧_
- WPF集合控件实现分隔符(ItemsControl Separator)_实用技巧_
- VS2012/VS2013本地发布网站问题集锦(HTTP错误代码)_实用技巧_
