mvcScaffolding / EF Code First 为相关表创建列,就像插入相关表一样
您好,我正在使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不确定,[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.