StackOverflowException - Adding fk to Events table


I’m using “DHTMLX Scheduler NET” (with Entity Framework) and I added a fk (ID_WorkPlace) to events table, but every time I try to load the scheduler data(check the code below):

public ContentResult Data() { var data = new SchedulerAjaxData(); .... // I get the error here data = new SchedulerAjaxData ( new CalendarioOficinaEntities().Events.Where(ev => ev.ID_WorkPlace == workPlaceID) ); .... return (ContentResult)data; }
I get the following error:

"System.StackOverflowException was unhandled Message: An unhandled exception of type 'System.StackOverflowException' occurred in mscorlib.dll"

But if I remove the connection in sql server and maintaining the “ID_WorkPlace” column everything run just fine.

What am I doing wrong?I can’t add fk to the Events table?

Thank you,
Rodrigo Campos

probably Event class has ‘WorkPlace’ property, which contains an instance of WorkPlace class and also have reference to related event which creates a circular reference.
Try removing WorkPlace property from ajax data, leaving only ID_WorkPlace … the_client