StackOverflowException on Getting scheduler data

I’m getting System.StackOverflowException on :

SchedulerAjaxData(events)

here is my code

[code]public ActionResult Data(int LeagueId, DateTime from, DateTime to)
{

        var lstCourtId = Db.Courts
            .AsNoTracking()
            .Include(i => i.League)
            .Where(w => w.League.LeagueID == LeagueId)
            .Select(c => c.CourtID).ToList();

        var events = Db.Events
                    .AsNoTracking()
                    .Include(i => i.Players.Select(s => s.Player))
                    .Include(i => i.Guests.Select(s => s.Guest))
                    .Where(w => lstCourtId.Contains(w.CourtID.Value))
                    .Where(w => w.end_date > from && w.start_date < to).ToList();

        return new SchedulerAjaxData(events);
    }[/code]

I think the problem can be because my “Recurring” object has “many to many” relation with Players and Guests.
If I comment the 2 includes, that work…

can you help me ?
can I see trace inside SchedulerAjaxData ?

Hello,
the issue seems to be caused by two-way links between Model classes, e.g. - Event.Players <-> Player.Events.
It creates a cyclic structure that can’t be serialized to JSON.
There are two solutions,

  1. manually specify properties that you’ll pass to the scheduler, using IQueryable.Select :

var events = Db.Events .AsNoTracking() .Include(i => i.Players.Select(s => s.Player)) .Include(i => i.Guests.Select(s => s.Guest)) .Where(w => lstCourtId.Contains(w.CourtID.Value)) .Where(w => w.end_date > from && w.start_date < to) // !!!here .Select(e => new {e.id, e.text, e.start_date, playerId = e.PlayerId, ...) .ToList();
2) Or, in your model class definition, you can mark some columns (event.Players, event.Guests) to be skipped by json serializer

[code]public class Event
{

[DHXJson(Ignore=true)]
public IEnumerable Players {get;set;}

[DHXJson(Ignore=true)]
public IEnumerable<Guest> Guests {get;set;}

}[/code]
scheduler-net.com/docs/loading-data.html

Thank you, I took the second solution and worked very well !

Hi How are you able to pass LeagueId to api Get() call ?? can you share details of client and serverside with example