简体   繁体   English

添加“使用实体框架的 controller”时未列出 Model 类

[英]Model classes are not listed when "a controller using Entity Framework" is added

I'm working on ASP.NET MVC test project.我正在研究 ASP.NET MVC 测试项目。 I decided to isolate my DataLayer from the main project.我决定将我的 DataLayer 与主项目隔离开来。

I added another project to my solution.我在我的解决方案中添加了另一个项目。 I created all my model classes (public access modifier).我创建了所有 model 类(公共访问修饰符)。 Then I created my context class so DbContext can make relationships with my models.然后我创建了我的上下文 class,这样DbContext就可以与我的模型建立关系。

Then, I created my repositories using interfaces and implemented them.然后,我使用接口创建了我的存储库并实现了它们。 I used Entity Framework to do migrations.我使用实体框架进行迁移。 Finally, I could create my code-first database in SQL Server.最后,我可以在 SQL 服务器中创建我的代码优先数据库。

Now, I want to add an admin area to my main project.现在,我想在我的主项目中添加一个管理区域。 After adding, I decided to add controllers using Entity Framework.添加后,我决定使用 Entity Framework 添加控制器。 But it doesn't list my DataLayer and its model classes in the list.但它没有在列表中列出我的 DataLayer 及其 model 类。 All the classes I've made have a namespace of "DataLayer".我创建的所有类都有一个名为“DataLayer”的命名空间。 I searched StackOverFlow and found a similar question but the answers did not solve my problem.我搜索了 StackOverFlow 并发现了一个类似的问题,但答案并没有解决我的问题。

How can I fix this?我怎样才能解决这个问题?

My solution:我的解决方案:

在此处输入图像描述

在此处输入图像描述

I solved it.我解决了。 I referenced the first project in the second project.我在第二个项目中引用了第一个项目。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM