我创建了一个单独的类库项目来存储数据库上下文和模型类. 在同一解决方案中,我创建了一个ASP.NET MVC项目,并引用了类库项目,并在项目的Web.config文件中包括了数据库上下文的连接字符串.
I created a separate Class Library project to store the Database Context and Model Classes. In the same solution, I created an ASP.NET MVC project and referenced the Class Library project, as well as include the Connection String for the Database Context, in the project's Web.config file.
但是,当我尝试添加控制器(使用EF使用视图)时,出现以下错误:
However, when I attempt to add a Controller (with views, using EF), I get the following error:
调用的目标已引发异常.
Exception has been thrown by the target of an invocation.
我能够在添加控制器"下拉框中看到数据库上下文和模型类",所以我认为这不是一个引用问题.
I am able to see the Database Context and Model Classes in the Add Controller drop down boxes, so I don't think its a referencing issue.
如果任何人(使用此配置)也遇到此错误,将非常感谢您的帮助.
If anyone is also experiencing this error (with this configuration), you assistance will be greatly appreciated.
推荐答案我定义了多个ConnectionString.我从我的类库中删除了默认值,并将其替换为ConstringStrings.现在工作正常!
I had more than one ConnectionStrings define. I removed the default and replaced it with the ConstringStrings from my Class Library. Works fine now!
从以下帖子中获得的解决方案:应用程序无法支撑项目
Solution taken from the following post: Application can't scaffold items
更多推荐
脚手架控制器抛出的调用目标已引发异常
发布评论