In this situation:
var allCustomers = from c in customers select c;
var oldCustomers = from o in allCustomers where o.age > 70 select o;
Will where clause reach database?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
I think you mean:
And Yes, it will reach the database.
Try using LINQPad to see the SQL code generated. Here’s an example:
I have a
Actortable that has the fields:Id | Name | AgeThe code:
gets translated to:
so you can see how it mixes the two queries in only one.
Remember, IEnumerables are lazy, so you unless their elements have to be known (because you iterate through them, or because you do
.Count()to see how many items are, etc), it won’t perform any query/operation.