Entity Framework: Multiple Claims Plan

I plan to prepare some methods that returned to me an already filtered collection of elements in the database table, and then execute queries in these collections. I am wondering if the first filtering will be performed as a separate statement or whether it will be combined.

eg.

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 get into the database once or twice?

thank

+3
source share
1 answer

IQueryabletranslates to sql only when accessing a collection of results. This is because your code hit the DB once. This section explains this point.

+2
source

Source: https://habr.com/ru/post/1795405/


All Articles