C# .NET - i want an architecture diagram for Linq how it reduces the hits to database

Asked By Myla Rajani on 02-Aug-12 08:34 PM
Hi all

By using Linq we can reduce the number of hits to database.

Suppose there are 10 records, based on the filter we have to get the corresponding records. let the name of th filter be status if the status is choosen as open, 4 records should be displayed and if the status is chosen as close 6 records should be displayed.

we can do it in 2 ways:
  1. we can hit the database on status change(more number of hits in this case) 
  2. we can write single stored procedure then using linq we can filter the data

By using this we can reduce hits.. I want a architecture diagram how the linq is helping in reducing the hits to database...

Thanks in Advance
Robbe Morris replied to Myla Rajani on 02-Aug-12 08:44 AM
Reducing hits to the database would require your scheme to return all of the records once into a List<stuff> and then perform LINQ .Where and .OrderBy method calls against the List<stuff> (or other IEnumerable type). 

Whatever you heard or read regarding reducing trips to the database is based on this concept.  They were trying to communicate LINQ's query capabilities on collections instead of the old fashion technique of always requerying the database if you need to filter or change the order by.
Peter Bromberg replied to Myla Rajani on 02-Aug-12 03:53 PM
You are confusing LINQ's capabilities here:
 1. we can hit the database on status change(more number of hits in this case) 
  2. we can write single stored procedure then using linq we can filter the data  

If the status changes, your stored procedure is still going to have to be called again UNLESS you query out ALL the data first and then operate via LINQ to Objects to filter it in memory every time the status changes.
Myla Rajani replied to Robbe Morris on 07-Aug-12 03:09 AM
Thank u I need an architecture flow how Linq reducing the number of hits

Thanks in advance