【发布时间】:2014-02-24 17:01:53
【问题描述】:
正如标题所暗示的,我真的在为此苦苦挣扎。我知道脚手架功能并不完全支持开箱即用的这些关系,但我似乎无法让一个相当常见的场景工作。我首先使用代码和存储库模式。一些代码...
public class Product
{
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int Id { get; set; }
public string Sku { get; set; }
public string Name { get; set; }
public decimal PricePerUnit { get; set; }
public bool Available { get; set; }
public string Description { get; set; }
public int QuantityPerCarton { get; set; }
public int? DisplayOrder { get; set; }
public ICollection<Category> CategoryList { get; set; }
}
public class Category
{
public int Id { get; set; }
public int? ParentCategoryId { get; set; }
public string Name { get; set; }
public string UrlName { get; set; }
public int? DisplayOrder { get; set; }
public bool Visible { get; set; }
public virtual ICollection<Product> Products { get; set; }
}
所以我想要两个对象之间的多对多关系。第一个问题。一旦我添加了虚拟集合,我就会得到'支持'上下文'上下文的模型自数据库创建以来已经改变'。即使在我执行迁移等之后也会发生这种情况。
其次,我不太明白(一旦可行),如何将这些列表放入视图中。似乎没有完美的首选资源来解释这一点。任何人都可以对此或端到端示例进行更具体的说明吗?
这应该很简单!!
谢谢
【问题讨论】:
标签: asp.net asp.net-mvc entity-framework entity repository-pattern