Is this a LINQ lazy loading problem? -


Something is odd in my program:

I query this agt.DefaultNr == 1 and get 3 items as a result:

  IEnumerable & lt; Agent & gt; In the candidates created by FavAgents = agt, select agt.DefaultNr == 1;  

For each item, I have set DefaultNr = 0

  foreach (agent nofollow error in favents) {noFavAgt .DefaultNr = 0; }  

I do another query but for some reason my favAgents collection is now empty!

  IEnumerable & lt; Agent & gt; SmallAgents = (where the agt.tempResultCount & lt; 30 orderbay agt.tempResultCount descending selection agt with AGT in FAV's agent);  

What's going on here?

Is this a LINQ lazy loading problem?

It looks like there will be a query again, after which I set all items = 0 because my collection is empty!

This is not lazy loading , it deferred Execution is . When you define your initial number, then you are not defining query , archive you are right that it is displaying a requery; Every time you repeat on favAgents , it will execute the query that you define. If you want to create a list based on the query that does not change, add ToList () .

  var favAgents = (Agents created from AGT where agt .efaultNr == 1 choose AGT) .Oolist ();  

By doing so, a list will be created in memory and the result will cache the query at that time.


Comments