K0unna
K0unna
CC#
Created by K0unna on 5/28/2023 in #help
✅ I get Internal Server Error when uses Include
[HttpGet]
public async Task<ICollection<Product>> Get()
{
var reviews = await _context.reviews.ToListAsync();
var products = await _context.products.ToListAsync();
List<ProductReviewModel> PRML = new List<ProductReviewModel>();
foreach (var i in products)
{
ProductReviewModel PRM = new ProductReviewModel()
{
Product = i
};

PRM.Review = reviews.FindAll(x => x.ProductId == i.Id);

PRML.Add(PRM);
}
return products;
}
[HttpGet]
public async Task<ICollection<Product>> Get()
{
var reviews = await _context.reviews.ToListAsync();
var products = await _context.products.ToListAsync();
List<ProductReviewModel> PRML = new List<ProductReviewModel>();
foreach (var i in products)
{
ProductReviewModel PRM = new ProductReviewModel()
{
Product = i
};

PRM.Review = reviews.FindAll(x => x.ProductId == i.Id);

PRML.Add(PRM);
}
return products;
}
In this code I get InternalServerError. Also if I use Include instead of whole this code, then I get InternalServerError again
20 replies