i have 2 table .
Product and Category .
Category :
public string CategoryName { get; set; }
public ICollection<Product> Products { get; set; }
Product :
public string ProductName { get; set; }
[Required]
public string ProductDescription { get; set; }
[Required]
public int CategoryId { get; set; }
public Category Category { get; set; }
and this is mapping :
public class ProductMapping : IEntityTypeConfiguration<Product>
{
public void Configure(EntityTypeBuilder<Product> builder)
{
builder.HasOne(c => c.Category).WithMany(x => x.Products).HasForeignKey(x => x.CategoryId);
}
}
but when i need to return detail of product with CategoryName
then i write this query :
var findProduct = await ProductEntity.Include(x => x.Category).Where(x => x.Id == key).FirstOrDefaultAsync();
but in result it show me this error :
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
whats the error ? how can i solve this problem ???