0
votes

Environment:

  • .net 4.6 1.0.0-rc1-update2
  • Entity Framework core rc final.

My API controller is throwing this exception:

An unhandled exception was thrown by the application. Newtonsoft.Json.JsonSerializationException: Self referencing loop detected for property 'Site' with type 'Blog.Model.Site'. Path '[0].Menus[0]'.

How can I implement the fixes suggested here: JSON.Net Self referencing loop detected

As far as I know, EF core does not implement lazy loading or proxy creation.

My controller simply returns the collection generated by this query:

public async Task<List<Site>> GetActiveSites()
{
    var query = db.Sites.Where(x => x.Active)
        .Include(x => x.Menus)
        .ThenInclude(m => m.MenuContentItems)
        .ThenInclude(x => x.ContentItem);

    return await query.ToListAsync();
}

Where:

  • Site(1) - Menu(*)
  • Menu(1) - MenuontentItem(*)
  • MenuContentItem(*) - ContentItem(1)
1
stackoverflow.com/questions/17313632/… See the answer provided by Stewart Hou.user3230660
did you find an actual solution for this?czioutas
@Drakoumel Yes, see link in comment above yours.user3230660
You might have a look at my answer on “Self Referencing Loop Detected” exception with JSON.Net page.Murat Yıldız

1 Answers

0
votes

Create a view model without the bi-directional mapping that EF has. Populate that view model from your your ef query.