score:4

Accepted answer

if i have multiple accesses to customers ( let us say that i use 4 foreach loops later on) will the get_all method be called 4 times? or are the results stored at the first execution?

each time you enumerate the enumerator (using foreach in your example), the query will re-execute, unless you store the materialized result somewhere. for example, if on the first query you'd do:

var customersource = new customerdao();
list<customer> customersource.where(customer => customer.code.equals("code1")).tolist();

then now you'll be working with an in-memory list<customer> without executing the query over again.

on the contrary, if each time you'd do:

var filteredcustomers = customersource.where(customer => customer.code.equals("code1"))
foreach (var customer in filteredcustomers)
{
    // do stuff
}

then for each enumeration you'll be exeucting the said query over again.

also is it more efficient (time wise because memory wise it is probably not) to just keep the get_all() method and use linq to filter the results? or use my existing setup which in effect executes

that really depends on your use-case. lets imagine you were using linq to ef, and the customer table has a million rows, do you really want to be bringing all of them in-memory and only then filtering them out to use a subset of data? it would usually be better to full filtered query.


Related Query

More Query from same tag