简体   繁体   English

无法使用实体框架使用操作创建控制器

[英]Cannot create Controller with actions using Entity Framework

I've created a Model using Model first and Entity Data Model of Entity Framework. 我已经使用实体模型的第一个模型和实体数据模型创建了一个模型。 Well, when I want to create the controller (right click on controllers folder Add->controller->WebApi 2 Controller with actions using EF) then I become after defining the inputfields an error message: there was an error getting the type "WebApi.Models.QR_Name". 好吧,当我想创建控制器时(右键单击controllers文件夹Add-> controller-> WebApi 2 Controller,其中包含使用EF的操作),然后在定义输入字段后出现错误消息:获取类型为“ WebApi。 Models.QR_Name”。 Try rebuilding the project. 尝试重建项目。 The same error getting by the other Model class. 由其他Model类获得的相同错误。 How can I solve this?? 我该如何解决?


EDIT: 编辑:

I have two classes: //Group 我有两个班://组

namespace WebApi.Models
{
    public partial class QR_Group
    {
        public QR_Group()
        {
            this.QR_Name = new HashSet<QR_Name>();
        }

        public int Id { get; set; }
        public string name { get; set; }
        public string code { get; set; }

        public virtual ICollection<QR_Name> QR_Name { get; set; }
    }
}

//Name //名称

namespace WebApi.Models
{
    public partial class QR_Name
    {
        public int Id { get; set; }
        public string firstname { get; set; }
        public double maxAge { get; set; }
        public int QR_GroupId { get; set; }

        public virtual QR_Group QR_Group { get; set; }
    }
}

Additionally is here the Context class: 另外这里是Context类:

namespace WebApi.Models
{
    public partial class WebApiContext : DbContext
    {
        public WebApiContext()
            : base("name=WebApiContext")
        {
        }

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            throw new UnintentionalCodeFirstException();
        }

        public virtual DbSet<QR_Group> QR_Groups { get; set; }
        public virtual DbSet<QR_Name> QR_Names { get; set; }
    }
}

在创建控制器之前,请按Ctrl + Shift + B组合键来构建您的解决方案,或转到“构建->构建解决方案”,然后尝试创建控制器。

暂无
暂无

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

相关问题 无法使用实体框架创建控制器 - Cannot create controller with Entity Framework 使用“Web Controller 2 with actions, using Entity Framework”加入咨询 - Join consult using "Web Controller 2 with actions, using Entity Framework" 无法引用实体框架,无法创建新控制器 - Cannot reference Entity Framework, cannot create new controller 无法使用Entity Framework创建迁移脚本 - Cannot create migration script using Entity Framework 无法使用Entity框架创建控制器 - 无法检索元数据 - Cannot create controller with Entity framework - Unable to retrieve metadata 无法使用实体框架创建控制器-无法检索“”的元数据 - Cannot create controller with Entity framework - Unable to retrieve metadata for ' ' 使用Web API 2 Controller创建控制器时未显示模型类,其中包含使用Entity Framework Database First的操作 - Model Class not showing when creating controller using Web API 2 Controller with actions using Entity Framework Database First .NET API 控制器控制器使用实体框架获取操作功能,但 PUT 和 POST 给出缺少响应 - .NET API Controller controller using Entity Framework Get actions functionnal, but PUT and POST give missing responses API Controller 使用实体框架值的操作不能是 null - API Controller with action using Entity Framework value cannot be null 使用实体框架添加具有读/写操作和视图的控制器会导致警告 - Adding a controller with read/write actions and views using entity framework results in a warning
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM