我在Visual Studio 2012中使用实体框架代码第一技术这是我的上下文
public class BakingWebContext : DbContext
{
public DbSet<Recipe> Recipes { get; set; }
public DbSet<Category> Categories { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
我有一个分类
public class Category
{
[Key]
public int CategoryId { get; set; }
[Required]
public string Name { get; set; }
public string Description { get; set; }
public string ImageUrl { get; set; }
public virtual ICollection<Recipe> Recipes { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
它包含一个虚拟的食谱集合
public class Recipe
{
[Key]
public int RecipeId { get; set; …
Run Code Online (Sandbox Code Playgroud)