1
这将创建两个表“配料”和“配方”以及用于多对多映射的附加表。实体框架中的配方 - 配料数据库ASP.NET MVC
public class DC : DbContext {
public DbSet<Ingredient> Ingredients { get; set; }
public DbSet<Recipe> Recipes { get; set; }
}
public class Ingredient {
public int Id { get; set; }
public string Name { get; set; }
public virtual ICollection<Recipe> Recipes { get; set; }
}
public class Recipe {
public int Id { get; set; }
public string Name { get; set; }
public virtual ICollection<Ingredient> Ingredients { get; set; }
}
问题:我想在实体框架创建的第三个映射表中包含额外的列“数量”。如何做到这一点?提前致谢。
感谢您的帮助,但由于我是新来的实体框架,我有一个问题关于您提供的RecipePart类。应该是:“公共配料成分{get; set;};”或“公共int IngredientID {搞定;设置;}”? – Acute 2012-02-17 11:26:28
@Acute:我不能说,我害怕 - 我自己对EF的了解不够。 – 2012-02-17 20:39:31