Here is a code snippet
IEnumerable<Car> GetCars()
{
foreach(var request in RequestQueue())
{
RemoveFromQueue(request);
yield return MakeCar(request);//Expensive
}
}
//Usage Scenario 1: No Problem
foreach(Car c in GetCars())
{
//Do stuff
}
//Usage Scenario 2: Problem, I have constructed all cars, but want only 1.
foreach(Car c in GetCars().Where(p=>p.Request.Id==10000))
{
//Do stuff
}
Is it possible to implement Evaluating the Where clause before I go ahead and make a Car? How?
Obviously, the where clause can vary based on the client usage.
Motivation: When you do Linq to SQL, .Take(10) is transformed to Top(10) and the query is executed on the server. I want to achieve something like this.