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

发布于 2024-11-06 18:49:44 字数 1067 浏览 0 评论 0原文

您好,我正在使用 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,但这似乎不起作用,

非常感谢,非常

感谢

Hi i am using MVCScaffolding, with MySQL its a bit of a pain but i have this:

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

}

and

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

this is great and when i add a sub category, it creates a dropdwon of categories, but it also creates the column Category_CategoriesId this i dont want, i have tried to set scaffolding to false but this doesent seem to work eith

help very much appreciated

thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

比忠 2024-11-13 18:49:44

我不确定,[Column("name")] 怎么样?
我考虑过为您已经解决的问题添加 [Editable(false)] 。

帮助您关闭它

添加 [ForeignKey("CategoriesId")] 到子类别中的虚拟类别可以修复它。

I am not sure, what about [Column("name")]?
I tought about adding [Editable(false)] for what you have already solved.

to help you close it

Adding [ForeignKey("CategoriesId")] to virtual Categories in Sub Categories fixes it.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文