我在.net核心实体框架3.1应用程序中定义了两个类
房间和RoomTypes
公共教室{
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 {
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。
有人能说明这个问题吗?谢谢卢克
发布于 2020-01-18 16:19:30
我解决了这个问题:我的其中一个列名与表相同!
公共虚拟roomtype RoomType { get;set;},我的其中一个字段是RoomType。
希望这能防止某人经历痛苦,一开始很难被发现。
快乐的日子!
附注:在MVC5框架中,它防止了错误,它只是通过添加1来重命名字段。这在.net核心中不会发生。
https://stackoverflow.com/questions/59796010
复制相似问题