You can use the IEnumerable<T>
's Any
extension method here:
public IQueryable<Product> GetOrdersByID(string id)
{
return db.Products
.Where(p => db.Orders.Any(i => i.orderId == p.id && i.orderId == id));
}
NOTICE: Take on account that the Any
method has the complexity of O(N) and the full solution actually has the complexity of O(N•M) because for each Product
, in the worst-case, you might scan the full Orders
collection.