We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

Circular reference loading details

Hi,

I need show a grid in a page, and the deatils in other page. The main load works fine but when I load the details I get a circular reference error.

I've this classes:
 
    public partial class Incidencia
    {
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")]
        public Incidencia()
        {    
            IncidenciaMes = new HashSet<IncidenciaMes>();
        }

        public int ID { get; set; }

        [Column(TypeName = "date")]
        public DateTime Fecha { get; set; }

        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
        public virtual ICollection<IncidenciaMes> IncidenciaMes { get; set; }
    }        
    
    public partial class IncidenciaMes
    {        
        public int ID { get; set; }

        public int IDIncidencia { get; set; }
     
        [Column(TypeName = "date")]
        public DateTime Fecha { get; set; }

        public string Descripcion { get; set; }

        public virtual Incidencia Incidencia { get; set; }

    }

    
For load the main grid: Incidencias (it works fine)

public List<Incidencia> GetIncidencias()
{
    return new GNC_Model().Incidencia.ToList();
}


For load the incidencia's details

public Incidencia GetIncidencia(int id)
{
    return new GNC_Model().Incidencia.Where(p => p.IDIncidencia == id).First() as Incidencia;
}


The context configuration
public partial class GNC_Model : DbContext
{
        public GNC_Model()
            : base("name=DataModel")
        {
            this.Configuration.ProxyCreationEnabled = false;
            this.Configuration.LazyLoadingEnabled = false;
        }
}


The view

@model Incidencia

@(Html.EJ().Grid<IncidenciaMes>("gridIncidenciaMes")                    
                    .Datasource((IEnumerable<object>)Model.IncidenciaMes.ToList())
                    .Columns(c =>
                    {
                        c.Field("ID").Add();
                        c.Field("Fecha").Add();
                    })
                )


                


3 Replies

VA Venkatesh Ayothi Raman Syncfusion Team October 12, 2016 12:51 PM UTC

Hi Manolo, 

Thank you for contacting Syncfusion support. 

We have already discussed this and created a knowledge base documentation. Please refer to the documents from following link, 
And we suggest you to use view model to transfer data between a controller and a view

Regards, 
Venkatesh Ayothiraman. 



MA Manolo October 14, 2016 12:06 PM UTC

Ok, thanks!


VA Venkatesh Ayothi Raman Syncfusion Team October 17, 2016 04:23 AM UTC

Hi Manolo, 

Thanks for the update. 

We are happy to hear that your requirement is achieved. 

Thanks, 
Venkatesh Ayothiraman. 


Loader.
Live Chat Icon For mobile
Up arrow icon