I have two tables, MenuItem and SearchTerm. I have a foreign key on SearchTerm that is linked to the primary key on MenuItem.
I'm using the database-first approach with entity framework.
The result of the above is that the models generated will contain references to one another. This allows me to get all the data I need in a single statement
//Where() condition omitted for this example.
IList<MenuItem> menuItems = db.MenuItems.Include("SearchTerm").ToList();
This brings back the data I need. The issue I am having is that when trying to return this data through an ajax call, I get an error Self referencing loop detected in my response. I understand this happens because it is trying to serialize the json and is unable to do so.
Is there a way I can fetch the data so that it will only include the first two levels (MenuItem, MenuItem.SearchTerms), or is this something I should be setting on my ajax request?