再次尝试这个问题,因为我的第一次尝试几乎没有连贯性:p
所以我非常困惑并首先使用实体框架代码
我有森林课。
我有一个树类。
每个森林可以有很多树
当我尝试序列化时,我得到了循环引用
public class Forest
{
    public Guid ID { get; set; }  
    public virtual List<Tree> Trees { get; set; }
}
public class Tree
{
    public Guid ID { get; set; }
    public Guid? ForestId {get;set;}
    [ForeignKey("ForestId")]
    public virtual Forest Forest {get;set;}
 }
每个森林都有树,但并非每棵树都在森林中。我在做时遇到多重性错误
@(Html.Raw(Json.Encode(Model)))
模型是森林的地方
如果我做ForestIdaGuid而不是 aGuid?我得到循环参考错误。
我也试过受保护的覆盖无效
OnModelCreating(System.Data.Entity.ModelConfiguration.ModelBuilder modelBuilder) 
{ 
  modelBuilder.Entity<Forest>() 
  .HasMany(x => x.Tree) 
  .WithOptional() 
   .HasForeignKey(y => y.ForestId); 
}
提前致谢