到特定列的MVC映射

本文关键字:MVC 映射 | 更新日期: 2023-09-27 18:04:40

我有以下类:

[Bind()]
[Table("Actives", Schema = "Actives")]
public class Active
{
    [Key()]
    public int ID { get; set; }
    [Required(ErrorMessage="Du skal angive et nummer for denne aktiv.")]
    [DisplayName("Nummer")]
    public int Number { get; set; }
    [Required(ErrorMessage = "Du skal angive hvilken type aktiven er.")]
    [DisplayName("Aktiv-type")]
    [Column(TypeName = "int")]
    public ActiveType ActiveType
    {
        get;
        set;
    }
    [Column(TypeName = "int")]
    [DisplayName("Sted")]
    public Place Place
    {
        get;
        set;
    }
}

我如何指定我的"地方"answers"ActiveType"属性应该匹配到"Place_ID"answers"ActiveType_ID"列?

到特定列的MVC映射

我不确定我是否正确理解您的问题,但是您不能将Name属性用于Column属性吗?

[Required(ErrorMessage = "Du skal angive hvilken type aktiven er.")]
[DisplayName("Aktiv-type")]
[Column(TypeName = "int", Name="ActiveType_ID")]
public ActiveType ActiveType
{
    get;
    set;
}
[Column(TypeName = "int", Name="Place_ID")]
[DisplayName("Sted")]
public Place Place
{
    get;
    set;
}