AutoMapper throwing StackOverflowException when calling ProjectTo<T>() on IQueryable
<p>I have created classes using EF Code First that have collections of each other.
Entities:</p>

<pre><code>public class Field
{
    public int Id { get; set; }
    public string Name { get; set; }
    public virtual List&lt;AppUser&gt; Teachers { get; set; }
    public Field()
    {
        Teachers = new List&lt;AppUser&gt;();
    }
}

public class AppUser
{
    public int Id { get; set; }
    public string Email { get; set; }
    public string Password { get; set; }
    public string UserName =&gt; Email;
    public virtual List&lt;Field&gt; Fields { get; set; }
    public AppUser()
    {
        Fields = new List&lt;FieldDTO&gt;();
    }
}
</code></pre>

<p>DTOs:</p>

<pre><code>public class FieldDTO
{ 
    public int Id { get; set; }
    public string Name { get; set; }
    public List&lt;AppUserDTO&gt; Teachers { get; set; }
    public FieldDTO()
    {
        Teachers = new List&lt;AppUserDTO&gt;();
    }
}

 public class AppUserDTO
{
    public int Id { get; set; }
    public string Email { get; set; }
    public string Password { get; set; }
    public string UserName =&gt; Email;
    public List&lt;FieldDTO&gt; Fields { get; set; }
    public AppUserDTO()
    {
        Fields = new List&lt;FieldDTO&gt;();
    }
}
</code></pre>

<p>Mappings:</p>

<pre><code>Mapper.CreateMap&lt;Field, FieldDTO&gt;();
Mapper.CreateMap&lt;FieldDTO, Field&gt;();
Mapper.CreateMap&lt;AppUserDTO, AppUser&gt;();
Mapper.CreateMap&lt;AppUser, AppUserDTO&gt;();
</code></pre>

<p>And I am getting StackOverflowException when calling this code (Context is my dbContext):</p>

<pre><code>protected override IQueryable&lt;FieldDTO&gt; GetQueryable()
{
    IQueryable&lt;Field&gt; query = Context.Fields;
    return query.ProjectTo&lt;FieldDTO&gt;();//exception thrown here
}
</code></pre>

<p>I guess this happens because it loops in Lists calling each other endlessly. But I do not understand why this happens. Are my mappings wrong?</p>