Reputation: 8639
I'm planning on preparing some methods that returned me an already filtered collection of elements in a DB table, and then execute queries on those collections. I'm wondering if the first filtering will be executed as a separate statement or will it be joined.
e.g.
public IQueryable<Person> GetAlivePersons(){
return db.Persons.Where(p => !p.IsDeceased);
}
public IQueryable<Person> GetElderPeople(){
return GetAlivePersons().Where(p => p.Age > 75);
}
Will the second method hit the DB once or twice?
Thanks
Upvotes: 3
Views: 430
Reputation: 7744
IQueryable
is translated in sql only when you accessing result collection.
That because your code hit DB once. This topic explains this point
Upvotes: 2