Code first scaffolding .net core 3.1 not working correctly

asp.net-core-scaffolding entity-framework-core

Question

I have 2 classes that I have defined in my .net core entity framework 3.1 application

Room and RoomTypes

public class Room {

    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; }


}

and RoomTypes

public class RoomType {

    public int RoomTypeId { get; set; }

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

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

}

But when I scaffold my models, the lookup field (RoomType) shows the ID field and not the type. If I scaffold the exact same in MVC 5, it does it correctly and the lookup field shows type and not the ID.

Can anyone shed light on this issue ?? Thanks Luke

1
0
1/17/2020 11:18:23 PM

Popular Answer

I solved the issue: One of my columns name was the same as the table!!

public virtual RoomType RoomType { get; set; } and one of my fields was roomtype.

Hope this prevents someone from going through the misery, at first very hard to spot.

Happy days!

P.S. With MVC 5 scaffolding, it prevents error, it just renames the field by adding a 1. This does not happen in .net core.

0
1/18/2020 8:19:29 AM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow