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 Query
- 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
- Net Core 3.1 Entity Framework: Get all records where a property is NOT included
- 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
More Query from same tag
- Dynamically Sorting with LINQ
- Cannot assign LINQ query to variable
- LINQ - group by, then sum conditionally
- Using linq and lambda to filter two collections
- Selecting all x which are in y table
- C# WPF Linq Join 4 tables and Where with varying parameters
- Passing propertyName, Condition Operator and Value to Function as a Linq query C#
- Processing a C# Dictionary using LINQ
- Calculate Sum of column using groupby
- LINQ lookup if table column contains value and return list of objects
- Gettting Object reference not set to an instance of an object. using linq c# datatable angularjs?
- How to use condition checking inside LINQ select new{ }
- AddDays is LINQ to SQL
- LINQ Statement foreach hour in day issue
- Replace a JSON value of a property in several JObjects
- Entity Framework 4.1 Modifying Object and Child Collection
- linq: how to get records update within 1 minute?
- How to join 2 row together in a same dictionary c#
- How to combine two expressions: result = exp1(exp2);
- C#, LINQ a generic sort method to sort a list by object properties and nested properties
- C# Create lambda expression with Left and right Join with 3 tables
- Linq to CSV : Convert data to .CSV file and return file from an action without saving file on the server
- MVC C# binding a linq to sql object with a one to many relation for the edit page
- LINQ to count number of rows in link table
- LINQ and various joining sample
- Custom LINQ-style implementation
- LINQ to SQL GroupBy Max() lambda
- How to exclude one object type from a Linq query
- get's ArgumentException only when doing async call to database in c# using linq QueryableExpression
- Having trouble grouping columns in Linq query with multiple joins