I\'ve been working for the first time with the Entity Framework in .NET, and have been writing LINQ queries in order to get information from my model. I would like to progr
Sometimes it might be a good idea to "cache" a LINQ query using ToList()
or ToArray()
, if the query is being accessed multiple times in your code.
But keep in mind that "caching" it still calls a foreach
in turn.
So the basic rule for me is:
foreach
(and thats it) - then I don't cache the queryforeach
and in some other places in the code - then I cache it in a var using ToList/ToArray