问题
I have created an .Net Core MVC6 application targeting net461. I have used a project structure I am very familiar with in which I place the data, model, and service classes in separate class library projects and the Web project references these.
When I attempt to scaffold a controller I receive an error that multiple matching types exist for the model I am scaffolding.
If I move all code to a single project, scaffolding is successful. If I move the context to Web project and leave the model in a separate project, I receive an error the NO matching types were found.
Has anyone else seen this same issue? Is there a workaround to still use this type of architecture?
Update
I started another project and always get this issue. I get this error when only using 1 extra project for the models. Attached is the error I recieve.
Scaffolding Error
Update 2
When the context and model are in the same project I receive this error.
Error editing dbContext
回答1:
Cannot post a comment, so I've to write an answer instead. I also had the same issue and opened it on Scaffolding github repository. Here's the 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.
Plus they also opened this issue as a bug, quoting:
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:
Hence, as of RC2, this is a bug in scaffolding tooling.
来源:https://stackoverflow.com/questions/37645827/scaffolding-in-net-core-with-multiple-projects-in-solution