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
- How to test post method in fiddler?
- C#: need to get all 'SampleData' for which "SampleDataConfig" config = Client
- LINQ MVC 3 and double query in profiler
- Return Max value with LINQ Query in VB.NET?
- The Type of one of the Expression in the join clause is incorrect.Type inference failed in the call to join
- Filter by criteriums in linq query
- Using Linq Select to create a new inherited object
- Create a datatable on the basis of a column of another Datatable Groupby using linq?
- How can I query a DbSet so that it returns both Local and non-Local data
- LINQ Get Count of 2nd level detail table
- Why does Enumerable.All return true for an empty sequence?
- Is LINQ Join operator using Nested Loop, Merge, or HashSet Joins?
- LINQ to Entities does not recognize the method 'Int32 Next()' method
- When calling multiple join conditions getting Error
- Find foreign key matching multiple row values using linq
- Is it possible to query list of ExpandoObject?
- A datatable that references a union of another datatable C#
- How can I return variable column lengths via LINQ to SQL
- Linq to entities, How to select all columns and also select custom columns?
- LINQ statement, select field that has specific attribute
- Linq results to a var does not populate values unless refreshed manually
- binding LINQ Query on post back has rows but doesn't display on screen
- IQueryable<T> to return a single record
- C# LINQ TimeSpan Average Days
- Linq query and get aggregated result + extra info
- Alternative to nested select statements
- Querying to linq and displaying it to view
- Filtering a list using except on multiple properties
- Scott Gu Dynamic Linq Convert Datetime to ShortDatetime
- Simple Linq query has duplicated join against same table?