0

Okay I'm new to EF and I'm having issues grasping on filtering results...

I'd like to emulate the ef code to do something like:

select * 
from order o  
    inner join orderdetail d on (o.orderid = d.orderid)
where d.amount > 20.00

just not sure how this would be done in EF (linq to entities syntax)

2 Answers 2

1

Your SQL gives multiple results per order if there's multiple details > 20.00. That seems wrong to me. I think you want:

var q = from o in Context.Orders
        where o.OrderDetails.Any(d => d.Amount > 20.00)
        select o;
Sign up to request clarification or add additional context in comments.

Comments

0

I would do it like that:

context.OrderDetails.Where(od => od.Amount > 20).Include("Order").ToList().Select(od => od.Order).Distinct();

We are taking details first, include orders, and take distinct orders.

2 Comments

That gives different results than his SQL, but I think his SQL is buggy, so it's hard to tell.
That gives the same result. It return only details with amount > 20 and adds their orders.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.