Edit2:
After finally being able to profile the two against each other, it appears that in my situation .AsQueryable() is slightly faster than Expression.Compile().
Original question:
I have implemented a cache of some database tables (as List<T>
) that I need to query with the same Expression<Func<T, bool>>
as I would use when querying against the Table<T>
itself.
What is the fastest/best way of these:
List<T>.AsQueryable().FirstOrDefault(Expression<Func<T, bool>>)
or
List<T>.FirstOrDefault(Expression<Func<T, bool>>.Compile())
?
Edit: Changed Where to FirstOrDefault, as that is the method I'm using. I guess I was a little tired when I wrote the question. Will FirstOrDefault examine every item once like Where, or does it actually stop on the first hit (if any)?