首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Code first scaffolding .net core 3.1无法正常工作

Code first scaffolding .net core 3.1无法正常工作
EN

Stack Overflow用户
提问于 2020-01-18 07:18:24
回答 1查看 284关注 0票数 0

我在.net核心实体框架3.1应用程序中定义了两个类

房间和RoomTypes

公共教室{

代码语言:javascript
复制
    public int RoomId { get; set; }

    [StringLength(250)]
    public string Roomname { get; set; }

    [StringLength(450)]
    public string RoomDescription { get; set; }

    [StringLength(50)]
    public string Rate { get; set; }

    [StringLength(50)]
    public string RateSpecial { get; set; }

    public bool? Available { get; set; }

    [StringLength(350)]
    public string PhotoPath { get; set; }

    public bool? Internet { get; set; }

    public bool? TVSet { get; set; }

    public bool? ElectronicSafe { get; set; }

    public bool? TeaCoffee { get; set; }

    public bool? Linnin { get; set; }

    public int? RoomTypeId { get; set; }

    public virtual RoomType RoomType { get; set; }


}

和RoomTypes

公共类RoomType {

代码语言:javascript
复制
    public int RoomTypeId { get; set; }

    [Column("RoomType")]
    [StringLength(90)]
    public string RoomType1 { get; set; }

    public virtual ICollection<Room> Rooms { get; set; }

}

但是当我搭建模型框架时,查找字段(RoomType)显示的是ID字段,而不是类型。如果我在MVC5中搭建了完全相同的脚手架,它会正确地执行,并且查找字段显示的是类型而不是ID。

有人能说明这个问题吗?谢谢卢克

EN

回答 1

Stack Overflow用户

发布于 2020-01-18 16:19:30

我解决了这个问题:我的其中一个列名与表相同!

公共虚拟roomtype RoomType { get;set;},我的其中一个字段是RoomType。

希望这能防止某人经历痛苦,一开始很难被发现。

快乐的日子!

附注:在MVC5框架中,它防止了错误,它只是通过添加1来重命名字段。这在.net核心中不会发生。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/59796010

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档