Can someone explain why EF is failing here?
Message: System.InvalidOperationException: Cycle detected while auto-including navigations: ‘CatalogPage.Pages’. To fix this issue, either don’t configure at least one navigation in the cycle as auto included in OnModelCreating
or call ‘IgnoreAutoInclude’ method on the query.
What?
Model:
public class CatalogPage
{
[Key]
public int Id { get; init; }
public string? Name { get; init; }
public string? Layout { get; init; }
public int? RoleId { get; init; }
public int CatalogPageId { get; init; }
public int OrderId { get; init; }
public int IconId { get; init; }
public bool Enabled { get; init; }
public bool Visible { get; init; }
public ICollection<CatalogPage> Pages { get; init; } = [];
public ICollection<CatalogItem> Items { get; init; } = [];
}
I am auto loading Pages…
When I try and fetch like so, it fails:
var parentlessPages = await dbContext.Set<CatalogPage>()
.Where(x => x.CatalogPageId == -1)
.ToListAsync();