title: .Net Core 3.0 possible object cycle was detected which is not supported
body: <p>I have 2 entities that are related as one to many</p>
  
  <pre><code>public class Restaurant {
     public int RestaurantId {get;set;}
     public string Name {get;set;}
     public List&lt;Reservation&gt; Reservations {get;set;}
     ...
  }
  </code></pre>
  
  <pre><code>public class Reservation{
     public int ReservationId {get;set;}
     public int RestaurantId {get;set;}
     public Restaurant Restaurant {get;set;}
  }
  </code></pre>
  
  <p>If I try to get restaurants with reservations using my api</p>
  
  <pre><code>   var restaurants =  await _dbContext.Restaurants
                  .AsNoTracking()
                  .AsQueryable()
                  .Include(m =&gt; m.Reservations).ToListAsync();
      .....
  
  </code></pre>
  
  <p>I receive error in response, because objects contain references to each other.
  There are related posts that recommend <a href="https://stackoverflow.com/questions/57885311/unusual-error-when-returning-list-of-results-from-api">to create separate model</a>
  or add <a href="https://stackoverflow.com/questions/57912012/net-core-3-upgrade-cors-and-jsoncycle-xmlhttprequest-error">NewtonsoftJson configuration</a> </p>
  
  <p>Problem is that I do not want to create separate model and 2nd suggestion didn't help.
  Is there any way to load data without cycled relationship ?
  *</p>
  
  <blockquote>
    <p>System.Text.Json.JsonException: A possible object cycle was detected
    which is not supported. This can either be due to a cycle or if the
    object depth is larger than the maximum allowed depth of 32.    at
    System.Text.Json.ThrowHelper.ThrowInvalidOperationException_SerializerCycleDetected(Int32
    maxDepth)    at System.Text.Json.JsonSerializer.Write(Utf8JsonWriter
    writer, Int32 originalWriterDepth, Int32 flushThreshold,
    JsonSerializerOptions options, WriteStack&amp; state)    at
    System.Text.Json.JsonSerializer.WriteAsyncCore(Stream utf8Json, Object
    value, Type inputType, JsonSerializerOptions options,
    CancellationToken cancellationToken)    at
    Microsoft.AspNetCore.Mvc.Formatters.SystemTextJsonOutputFormatter.WriteResponseBodyAsync(OutputFormatterWriteContext
    context, Encoding selectedEncoding)    at
    Microsoft.AspNetCore.Mvc.Formatters.SystemTextJsonOutputFormatter.WriteResponseBodyAsync(OutputFormatterWriteContext
    context, Encoding selectedEncoding)    at
    Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.g__Awaited|29_0[TFilter,TFilterAsync](ResourceInvoker
    invoker, Task lastTask, State next, Scope scope, Object state, Boolean
    isCompleted)    at
    Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Rethrow(ResultExecutedContextSealed
    context)    at
    Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.ResultNext[TFilter,TFilterAsync](State&amp;
    next, Scope&amp; scope, Object&amp; state, Boolean&amp; isCompleted)    at
    Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.InvokeResultFilters()</p>
  </blockquote>
  
  <p>*</p>