I need LINQ to grab a whole table, but this seems not to be working... everytime i select on the values via the pkey, a select is fired again..
So, actually this code:
DataContext dc = new DataContext();
dc.Stores.ToList();
Store st = dc.Stores.SingleOrDefault(p => p.Id == 124671);
is making a
select * from store
at the "ToList()" method and an ADDITIONAL
select * from store where id = 124671
at the selection part below it...
Of course, i want to prevent it to make the second select..
How would i do it? (I DON'T want to store the ToList() result in an additional property like List< Store > )
UPDATE:
Regarding your answers that would mean, that:
Store st = stores.SingleOrDefault(p => p.Id == 124671);
Store st = stores.SingleOrDefault(p => p.Id == 124671);
would trigger 2 selects to the DB, which would make the LINQ-idea useless?! Or what am i getting wrong here?
I thought LINQ would basically save all the data i grabbed in the selects and ONLY performs another request when the data was not found in the "cache".. So, i thought of it like some kind of "magical" storagelayer between my application and the database..
UPDATE #2
Just that you get the idea.. i want to lose the performance at the beginning ( when grabbing all data ) and win it back alter when i select from the "cached" data...