【发布时间】:2011-08-29 04:57:02
【问题描述】:
我有一个看起来像这样的模型:
public class Category
{
public string Id { get; set; }
public string Description { get; set; }
public Category Parent { get; set; }
public ICollection<Category> Children { get; set; }
public ICollection<Product> Products { get; set; }
}
有一个看起来像的数据库表
Categories
Id (PK varchar(5))
Description (nvarchar(50))
ParentId (FK varchar(5))
但是在设置映射时我很难过
modelBuilder.Entity<Category>()
.HasMany(x => x.Children)
.WithMany(x => x.Children)
.Map(m =>
{
m.ToTable("Categories");
m.MapLeftKey(x => x.Id, "Id");
m.MapRightKey(x => x.Id, "ParentId");
});
我可以看到映射失败的原因 (StackOverflowException),但不确定如何修复它。任何帮助将不胜感激。
这是使用最新版本的 EF(4.1?)。
谢谢!
【问题讨论】:
标签: mapping ef-code-first entity-relationship entity-framework-4.1