1
I’m starting in c# and I’m having some difficulties with Entity-Framework. I have the following scenario:
public InstituicaoMap()
{
// Primary Key
HasKey(t => t.IdInstituicao);
// Properties
Property(t => t.Nome)
.IsRequired()
.HasMaxLength(255);
}
public CampanhaMap()
{
// Primary Key
this.HasKey(t => t.IdCampanha);
// Properties
this.Property(t => t.Texto)
.IsRequired()
.HasMaxLength(160);
this.Property(t => t.DataEdicao)
.IsFixedLength()
.HasMaxLength(8)
.IsRowVersion();
// Relationships
this.HasRequired(t => t.Instituicao)
.WithMany(t => t.Campanhas)
.HasForeignKey(d => d.IdInstituicao);
}
I am implementing a campaign CRUD, and at the moment I am working on the method "IEnumerable<Campanha> List()
" (listing all registered campaigns).
Apparently it is working. For every campaign returned in the "list" there is an Institution object inside. ae all right. The problem is that within the institution there is a list of campaigns, that there are institutions, that there is another list of campaigns... and so it goes.
1 - I am concerned about the memory consumption and/or some problem that this recursion may cause.
2 - I am sending this return to View via JSON (as grid paging will be done with AJAX/JSON).
return new ContentResult
{
Content = JsonConvert.SerializeObject(v),
ContentType = "application/json"
};
In this return, I am getting an "infinite looping" error from Jsonconvert. In fact, because the campaigns object is recursive.
What can I do?
Your question sounds a lot like a question I asked here:http://answall.com/questions/35109/serialize-objects-para-json-a-circular-reference-was-detected-while-s
– Marconi