I'm using entity framework core. I'm attempting to create a list of products and include associate reviews and review author data.
I have a 3 entities:
public class Product
{
[Key]
public int ID { get; set; }
public ICollection<Review> Reviews {get; set;}
}
public class Review
{
[Key]
public int ID { get; set; }
public Product Product {get; set;}
public Customer Author { get; set; }
}
public class Customer
{
[Key]
public int ID { get; set; }
public ICollection<Review> Reviews { get; set; }
}
When, refering to this answer, I request a list of products with reviews and authors:
context.Products.Include(p=> p.Reviews.Select(r => r.Author)).ToList();
The following error is thrown:
System.InvalidOperationException
Message = The property expression 'p => {from Review r in [p].Reviews select [r].Author}' is not valid. The expression should represent a property access: 't => t.MyProperty'
Any advice would be greatly appreciated.