.net core 3.1
JsonException: возможное Обнаружен цикл объектов, который не поддерживается. Это может быть связано либо с циклом, либо с тем, что глубина объекта превышает максимально допустимую глубину 32.
Вот мои коды:
Моя модель
Код: Выделить всё
public class Product
{
public int Id { get; set; }
public string Name { get; set; }
public string ProductText { get; set; }
public int ProductCategoryId { get; set; }
[JsonIgnore]
public virtual ProductCategory ProductCategory { get; set; }
}
Код: Выделить всё
public class ProductCategory
{
public int Id { get; set; }
public string Name { get; set; }
public string CatText { get; set; }
public string ImagePath { get; set; }
public int Priority { get; set; }
public int Viewd { get; set; }
public string Description { get; set; }
public bool Active { get; set; }
public DateTime CreateDate { get; set; }
public DateTime ModifyDate { get; set; }
public virtual ICollection
Products { get; set; }
}
Код: Выделить всё
public async Task GetAllProductAsync()
{
return await _context.Products.Include(p => p.ProductCategory).ToListAsync();
}
Код: Выделить всё
public interface IProductRepository
{
...
Task GetAllProductAsync();
...
}
Код: Выделить всё
[Route("api/[controller]")]
[ApiController]
public class ProductsController : ControllerBase
{
private readonly IProductRepository _productRepository;
public ProductsController(IProductRepository productRepository)
{
_productRepository = productRepository;
}
[HttpGet]
public ActionResult Get()
{
return Ok(_productRepository.GetAllProduct());
}
}
Я получил эту ошибку,
Я не могу ее устранить это.
Подробнее здесь: https://stackoverflow.com/questions/601 ... orted-this
Мобильная версия