Consider the below code
private List<Orders> GetOrders(int id)
{
var result = Context.Orders.Where(x => x.OrderId == 15)
.Include(x => x.Products)
.Include(x => x.CustomerDetails)
.ToList();
return result;
}
Products and CustomerDetails are Navigation properties on Orders Entity. I just want to get results with details about the most expensive product only.
So I tried below,
Context.Orders.Where(x => x.OrderId == 15)
.Include(x => x.Products.OrderByDescending(p => p.Price).Take(1))
.Include(x => x.CustomerDetails)
.ToList();
But this is resulting in an error,
An exception of type 'System.ArgumentException' occurred in EntityFramework.dll but was not handled in user code Additional information: The Include path expression must refer to a navigation property defined on the type. Use dotted paths for reference navigation properties and the Select operator for collection navigation properties.
How to resolve this issue?