Assume we have a method like this:
public IEnumerable<T> FirstMethod()
{
var entities = from t in context.Products
where {some conditions}
select t;
foreach( var entity in entities )
{
entity.SomeProperty = {SomeValue};
yield return entity;
}
}
where context is a DataContext that is generated by Linq to SQL designer.
Does "FirstMethod" load the data into memory from database (because of the foreach loop) or will it still defer-load it until another foreach loop that doesn't have "yield return" is found in another method like the following?
public void SecondMethod()
{
foreach( var item in FirstMethod() )
{
{Do Something}
}
}