Below is the model.
class Product
{
public int Id { get; set; }
public ICollection<Categorization> Categorization { get; set; }
}
class Categorization
{
public int ProductId { get; set; }
public Product Product { get; set; }
public int CategoryId { get; set; }
public Category Category { get; set; }
}
class Category
{
public int Id { get; set; }
public ICollection<Categorization> Categorization { get; set; }
}
I am trying to list down all the Products and their Category as well. API Code as below
foreach (var product in _context.Products.ToList()){
var categories = product.Categorization.Select(c => c.Category);
...
}
When we call the Api, I get this error:
System.ArgumentNullException: Value cannot be null.
Parameter name: source
at System.Linq.Enumerable.Select[TSource,TResult](IEnumerable1 source, Func
2 selector)