采用Entity Framework Code-First如何建立一对多关系?菜谱应用代码求指导
菜谱应用EF Code-First设计方向确认与改进建议请求
我正在为配偶开发一款菜谱应用,希望在应用迭代过程中,她能直接向数据库添加新菜谱。添加新菜谱时,她可通过三个下拉菜单分别选择食材、计量单位和数量来构建菜谱配料。目前我已采用Entity Framework Code-First方式完成以下代码,想确认这个方向是否正确?创建表、控制器和视图后,菜谱配料索引视图的显示效果如图所示,恳请各位提供改进建议。
public class Recipes { public int Id { get; set; } public string Name { get; set; } public string Description { get; set; } public string Image { get; set; } } public class UnitsModel { [Key] public int Id { get; set; } public string UnitName { get; set; } } public class UnitQty { [Key] public int Id { get; set; } public string Name { get; set; } } public class IngredientsModel { [Key] public int Id { get; set; } public string Name { get; set; } } public class RecipeIngredients { public int Id { get; set; } public int RecipesId { get; set; } [ForeignKey("RecipesId")] public Recipes Recipes { get; set; } public int IngredientsModelId { get; set; } [ForeignKey("IngredientsModelId")] public IngredientsModel IngredientsModel { get; set; } public int UnitQtyId { get; set; } [ForeignKey("UnitQtyId")] public UnitQty UnitQty { get; set; } public int UnitsModelId { get; set; } [ForeignKey("UnitsModelId")] public UnitsModel UnitsModel { get; set; } }

内容的提问来源于stack exchange,提问作者Marcus
相关产品推荐
相关产品推荐

