mvcScaffolding / EF Code First为相关表创建列,就像插入相关表一样

时间:2011-05-10 14:57:34

标签: asp.net-mvc entity-framework asp.net-mvc-3 ef-code-first scaffolding

您好我正在使用MVCScaffolding,MySQL有点痛苦,但我有这个:

public class SubCategories
{
    [Key, Display(Name = "ID"), HiddenInput(DisplayValue = false), Required]
    public Int32 SubCategoriesId { get; set; }

    [Required, Display(Name = "Name")]
    public string SubCategoriesName { get; set; }

    [Required, Display(Name = "Active")]
    public bool SubCategoriesShow { get; set; }

    [Required, Display(Name = "Category")]
    public Int32 CategoriesId { get; set; }

    [ScaffoldColumn(false)]
    public virtual Categories Categories { get; set; }

}

public class Categories
{
    [Key, Display(Name = "ID"), HiddenInput(DisplayValue = false), Required]
    public Int32 CategoryId { get; set; }

    [Required,Display(Name = "Name")]
    public string CategoryName { get; set; }

    [Required,Display(Name = "Active")]
    public bool CategoryShow { get; set; }
}

这很好,当我添加一个子类别时,它会创建一个类别的dropdwon,但它也创建了我不想要的列Category_CategoriesId,我试图将脚手架设置为false但是这个doesent似乎工作了

非常感谢

感谢

1 个答案:

答案 0 :(得分:1)

我不确定,[Column(“name”)]怎么样? 我想为你已经解决的问题添加[可编辑(假)]。

帮你关闭它

将[ForeignKey(“CategoriesId”)]添加到子类别中的虚拟类别会修复它。