Wilky
Wilky

Reputation: 209

Entity Framework ObjectSet

Quick question. Take the following method I wrote for my EF repository:

public virtual IEnumerable<T> SelectWhere(Expression<Func<T, bool>> predicate)
{
    using (CAMHS_DB db = new CAMHS_DB())
    {
        return db.CreateObjectSet<T>().Where(predicate).ToList<T>();
    }
}

Will EF apply my predicate before it goes to the DB and use it to return only the records I asked for, or will it return everything then apply the predicate??

Thanks, Wilky.

Upvotes: 0

Views: 607

Answers (1)

Shahar Gvirtz
Shahar Gvirtz

Reputation: 2438

In your code sample, he'll use the predicate as part of the select statement and select only the asked records.

BUT, you should be aware that after you use the "ToList()" method, if you'll take the returned value from this method and use the "Where" extension method on it, it'll be against the data that already in the memory.

Upvotes: 4

Related Questions