最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
VS2017添加EF的MVC控制器报错解决方法
时间:2022-06-25 05:32:59 编辑:袖梨 来源:一聚教程网
VS2017添加EF的MVC控制器报错的解决方法,供大家参考,具体内容如下
1. 错误描述:no database provider has been configured fot this DbContext.
此类错误是上下文的注册造成的.解决方式在DBContext中重写OnConfiguring方法去注入数据库连接.
DbContext中:
publicstaticstringConnectionString {get;set; }
protectedoverridevoidOnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.UseSqlServer(ConnectionString);
base.OnConfiguring(optionsBuilder);
}
在Startup.cs中
publicvoidConfigureServices(IServiceCollection services)
{
// Add framework services.
var sqlserverConnection = Configuration.GetConnectionString("SQLServerConnection");
DbContext.ConnectionString = sqlserverConnection;//将配置连接传入DbContext中
services.AddDbContext
services.AddMvc();
}
2.错误描述:Could not add Model type XXX to DbContext
错误描述没有注册DbSet属性.但实际上是有 public DbSet
相关文章
- 荒原曙光日升之冕有哪些功能 11-05
- 发朋友圈的句子 11-05
- 三国天下归心吕布有什么天赋及技能 11-05
- 二重螺旋风系阵容怎么搭配 11-05
- 神迹觉醒太阳神有哪些技能 11-05
- 三国望神州韩遂有什么玩法技巧 11-05