111,092
社区成员




public class Product //商品
{
public int Id { get; set; }
public string Name { get; set; }
public int Price { get; set; }
public int CategoryId { get; set; }
}
public class Category //分类
{
public Category()
{
products = new HashSet<Product>();
}
public int Id { get; set; }
public string Name { get; set; }
//导航属性
public ICollection<Product> products { get; set; }
}
using (var context = new KTStoreModel())
{
Category category = context.Categories.FirstOrDefault();
category.products = new List<Product>()
{
new Product(){Name = "高中英语",Price = 34},
new Product(){Name = "高中历史",Price = 25 }
};
context.SaveChanges();
}