score:2
First, this sounds like a obvious case for the speed rant:
https://ericlippert.com/2012/12/17/performance-rant/
Second:
The best way is to keep this in the Database. You are not going to beat the speed of a DB Query with Indexes designed for quick matching, by transfering the data over the network twice (once to get it, once to return it) and doubling the search load (once to get all odd ones, once to update all the ones you just changed). My standing advice is to always keep as much work as possible on the DB side. Your client code will never be able to beat it.
Third:
If you do need to use client side processing:
Now a lot of my answer depend on details of the implementation, how the JiT and general Compiler optimsiations work, etc.
Foreach uses works on enumerators, not Collections. But if you feed a collection to foreaach, a Enumerator is implicitly created. Now enumerators do have two properties:
- If the collection changes, the Enumerator becomes invalid. Most people learn about them because they ran into this issue.
- It is a extra function call and set of checks for accessing a collection. So it will be a slowdown. How much is hard to say, as the Optimisations and JiT are pretty good.
So you propably want to use for loop instead.
If you could turn the Dictionary into a collection where the Primary Key is used as Index, it might be a bit faster. But hat has the danger of running into a lot of "dry spells" regarding data, so it depends a lot on your source data.
Source: stackoverflow.com
Related Articles
- Mass Update a property on multiple records inside a dictionary (VB.NET / C#)
- Linq to SQL update multiple records in one query
- Linq to sql update multiple record from list of records
- update list property using linq join on dictionary
- Update class property inside Enumerable.Zip linq c#
- Properly using Linq.GroupBy on multiple key-value-pairs in a Dictionary property
- entity framework update multiple records using join
- .net linq update time part of datetime for multiple records
- How do I make my query return one another property inside dictionary
- Update Multiple Records Based on Multi-column Key
- Dynamics CRM Linq Update multiple records
- How to consolidate a Dictionary with multiple (three) keys by reducing one or more key and merging the multiple records (if any) into one single one?
- How to update property inside a object in C#
- How do I minimize C#, LINQ code in Deleting Multiple Records
- Use multiple left joins to set DTO property inside select new linq query
- Select multiple records based on list of Id's with linq
- C# - code to order by a property using the property name as a string
- how to update the multiple rows at a time using linq to sql?
- Using LINQ to Update A Property in a List of Entities
- Update records using LINQ
- How to select multiple values from a Dictionary using Linq as simple as possible
- update multiple elements at once LINQ
- How to Bulk Update records in Entity Framework?
- Best way to delete multiple records in a LINQ query?
- Using a partial class property inside LINQ statement
- Replacing nested foreach with LINQ; modify and update a property deep within
- LINQ In Line Property Update During Join
- Syntax to execute code block inside Linq query?
- EF - Update multiple rows in database without using foreach loop
- Deleting multiple records with Entity Framework using a single LINQ query
- Can I use anonymous types from linq results to create a collection of classes as part of a method parameter?
- How to filter a list based on a common property (only then to find the min value)
- LINQ Dynamic Query Library setup
- How to filter parent list<> when we apply condition on child list?
- LINQ To objects: Quicker ideas?
- How to insert new values in single column in sql databse
- GPS coordinates with Entity framework and LINQ
- Combining multiple linq queries and concatenated results into a smaller query
- Linq GroupBy how to return a collection of objects that are grouped into another list?
- Generate Dynamic Linq query using outerIt
- Solution For Updating LINQ to SQL Files After Database Schema Change
- Linq error when returning a List inside a List
- linq query where contains list of class
- Compare in Linq
- Query items based on size
- Linq: How to optimize a request with a table/list as parameter?
- Optimizing orderby sum in LINQ and Entity Framework
- How get the biggest number?
- Entity Framework, eager loading entites
- C# linq Files.ReadAllLines() fails for large 650MB CSV file