扬言炸地铁被判刑,天津楼市,河南农业职业学院数字化管理系统
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<dbcontext>(options => options.usesqlserver(sqlserverconnection)); services.addmvc(); }
2.错误描述:could not add model type xxx to dbcontext
错误描述没有注册dbset属性.但实际上是有 public dbset<xxx> xxx{ get; set; }注册的.将dbset<xxx>中的类改成<命名空间+类名>这种完整声明即可解决
更多精彩内容大家可以点击《visual studio 2017开发使用教程》,关于visual studio的安装教程可以点击《visual studio安装使用手册》进行学习,希望大家喜欢。
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持移动技术网。
如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复
asp.net搭建博客,使用BlogEngine.NET+MySql搭建博客
网友评论