score:4
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.
Source: stackoverflow.com
Related Query
- How does linq actually execute the code to retrieve data from the data source?
- How to retrieve data for two different portions of a single web page using LINQ from the same database table?
- How to understand the following C# linq code of implementing the algorithm to return all combinations of k elements from n
- C# LINQ How to get a data source from a db?
- How to swap the data source associated with a Linq query?
- How does the Entity Framework retrieve rows using LINQ with a predicate function?
- How to retrieve the values from list using indexes by linq query?
- How do I group items from a collection using LINQ and return the shaped data according the collection type
- How to execute code as a part of the LINQ query
- How do I use LINQ to return the first item from each set of Grouped data (In VB.Net)
- How to reinsert data from one table onto itself using LINQ in code migration?
- C# LINQ or for loop How to get a data source from a db?
- How to use Linq Aggregate Query to print line sequence number alongwith some data from the List<string>?
- How to convert the return type of the model data from Product entity to ProductViewModel objects using LINQ select?
- how to retrieve data from many to many relationship in mvc c# with linq
- How I get the right Data from my Column with Linq
- How to execute a linq query for each item in a list , use it in the where clause and return a collection from the result of each query?
- Using LINQ and Entity Framework, how can I just populate some properties of a Dbo with data from the DB?
- How does the EF use the callback provided in the LINQ `Where` function to select elements from DB?
- c# Linq or code to extract groups from a single list of source data
- How to retrieve data from XML using LINQ in VB.NET?
- how to fetch data from database using linq query for relationship 1:N and N:N (between 3 entity) in asp.net mvc EF code first?
- How can I populate data inside a LINQ .Select from the values of each character of a string?
- how to retrieve data from helper class property using Linq query C#
- Data paging in linq without removing records from the data source
- How does the following LINQ statement work?
- How can I filter a dictionary using LINQ and return it to a dictionary from the same type
- How does LINQPad reference other classes, e.g. Books in the LINQ in Action samples
- The data source does not support server-side data paging
- How does deferred LINQ query execution actually work?
More Query from same tag
- increase all values in list by one
- linq left outer join on lists
- Join Extension Method
- Why in c# can't we wrap anonymous objects in list of objects?
- Expression.Body.Expressions -- how to use it?
- c# dealing with all possible null and non null values
- How To Query A List Of Strings Using C#, Linq, and Mongo
- linq select C# to vb.net
- translating complex T-SQL query to LINQ to Entities
- Linq - Unsupported overload used for query operator 'Where' using a Predicate
- Merge data into single Dictionary after cross join of two list in c#
- LINQ: how to zip 2 lists and select elements where first list is distinct?
- Entity - how to get only one column
- How do write LINQ query to do recursion?
- How to find average when instances are grouped or categorized on multiple columns?
- Filter a property IENumerable to only include items that pass a test
- How do I write the Linq query to get complex model items?
- Calculate Player WinLoss Percentage
- Complex DTO to use in a View Model with MVC
- How can I use OrderBy<> in my LINQified Regex?
- How can I use ':' character in a name of XDocument element?
- How can I parse OWL file (containing RDF namespaces) with LINQ
- How do you get all X objects in all Y objects?
- Creating a datatable with only the rows that match a specific column name prefix using Linq in c#
- How to debug an empty LINQ result query?
- Handling 'Sequence has no elements' Exception
- OrderBy when a parent-value maybe null
- Retrieving an Entity Object by name - LINQ to Entities, EF 4.0
- Is there a better way to formulate this entity framework 4 update?
- Linq select nested rows