我创建了一个针对 net461 的 .Net Core MVC6 应用程序。我使用了一个我非常熟悉的项目结构,我将数据、模型和服务类放在单独的类库项目中,Web 项目引用这些。
当我尝试搭建 Controller 时,我收到一条错误消息,指出我正在搭建的模型存在多个匹配类型。
如果我将所有代码移动到一个项目中,脚手架就成功了。如果我将上下文移动到 Web 项目并将模型留在单独的项目中,我会收到一条错误消息,指出没有找到匹配的类型。
还有其他人遇到过同样的问题吗?是否有解决方法可以继续使用这种类型的架构?
更新
我开始了另一个项目,但总是遇到这个问题。仅对模型使用 1 个额外项目时出现此错误。附件是我收到的错误。
更新 2
当上下文和模型在同一个项目中时,我会收到此错误。
最佳答案
无法发表评论,所以我必须写一个答案。我也遇到了同样的问题,并在 Scaffolding github 存储库上打开了它。这是 response :
currently there is an issue with scaffolding, that it doesn't support model classes outside of the current project properly.
As a workaround, you can add the model temporarily to your web project and then move it to the BLL/ DAL projects after scaffolding.
另外他们还开了this issue as a bug , 引用:
Scaffolding fails if model class is in a dependency (project/ library) of the project on which scaffolding is being run. #251
Project A has a dependeny on Project B. Project B has model class If you try to run scaffolding on Project A by using model class from Project B, it fails with the below error: No model type returned for type:
因此,从 RC2 开始,这是脚手架工具中的错误。
关于c# - .Net Core 中的脚手架与解决方案中的多个项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37645827/