I'm starting in C # and I'm having some difficulties with the 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'm implementing a campaign CRUD, and I'm currently running the " IEnumerable<Campanha> List()
" method (which lists all registered campaigns).
Apparently this is working. For each campaign returned in the "list" there is an Institution object inside. Until then. 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 on.
1 - I'm worried about memory consumption and / or some problem that this recursion might cause.
2 - I'm sending this return to View via JSON (since grid pagination will be done with AJAX / JSON).
return new ContentResult
{
Content = JsonConvert.SerializeObject(v),
ContentType = "application/json"
};
On this return, I'm getting an "infinite looping" error from JsonConvert. In fact, because the campaign object is recursive.
What can I do?