我创建了一个名为 tbGeneralOptions 的表,其中包含对我的应用程序中问题的一些默认答案。选项为 Yes、No、N/A,其值分别为 1、2、3。
public class tbGeneralOption
{
public int tbGeneralOptionID { get; set; }
[Required(ErrorMessage = "Please enter an Option")]
[Display(Name = "Option")]
public string OptionName { get; set; }
public virtual ICollection<tbFamilyMember> tbFamilyMember { get; set; }
public virtual ICollection<tbFamily> tbFamily { get; set; }
}
在我的 tbFamilyMember 表中,我将上述选项中的值存储在 Disability 和 PhotoPermission 字段中。
public class tbFamilyMember
{
[Display(Name = "Family Member ID")]
public int tbFamilyMemberID { get; set; }
[Display(Name = "Family ID")]
public int tbFamilyID { get; set; }
[Required(ErrorMessage = "Please select a Role")]
[Display(Name = "Role")]
public int tbFamilyRoleID { get; set; }
[Display(Name = "Firstname")]
public string Firstname { get; set; }
[Display(Name = "Surname")]
public string Surname { get; set; }
[Required(ErrorMessage = "Please select if the Family Member has a disability")]
[Display(Name = "Disability")]
public int Disability { get; set; }
[Required(ErrorMessage = "Please select if the Family Member has given permission for photographs")]
[Display(Name = "Photo Permission")]
public int PhotoPermission { get; set; }
public virtual tbFamily tbFamily { get; set; }
public virtual tbFamilyRole tbFamilyRole { get; set; }
public virtual tbGeneralOption tbGeneralOption { get; set; }
}
我现在的问题是如何在我的视图中显示存储值的 OptionName。
我假设我可以通过外键建立链接,但如果字段名称不匹配,可以这样做吗?