Trying this question again because my first attempt was barely coherent :p
So I am super confused and using Entity Framework Code First
I have a Forest class.
I have a Tree class.
Each Forest can have many Trees
When I was trying to serialize I was getting circular reference
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;}
}
Every forest has trees but not every tree is in a forest. I struggle with either errors of Multiplicity when doing
@(Html.Raw(Json.Encode(Model)))
Where the model is a Forest
and if I make ForestId
a Guid
instead of a Guid?
I get Circular Reference errors.
I also tried protected override void
OnModelCreating(System.Data.Entity.ModelConfiguration.ModelBuilder modelBuilder)
{
modelBuilder.Entity<Forest>()
.HasMany(x => x.Tree)
.WithOptional()
.HasForeignKey(y => y.ForestId);
}
Thanks in advance