score:3
Accepted answer
You are correct, running db.Items.Single(...)
multiple times may be suboptimal.
Calling it once and then referencing its properties should be more efficient:
var item = db.Items.Single(t => t.Id == itemId);
item.TotalValue = 999;
item.CurrentValue = 99;
db.SaveChanges();
Source: stackoverflow.com
Related Articles
- linq extension methods, how to update multiple properties of a single item?
- Multiple WHERE Clauses with LINQ extension methods
- How to update a single item of liist of objects using LINQ in C#
- Why the extension method of where for LINQ in this code would print out a single number while it shouldn't print anything at all?
- Update only a single item in linq
- How to sort list on multiple properties in one line of code in Linq
- Update multiple fields using single linq statement
- C# Linq To Create Group On Multiple Properties and format the resultant group into single key/property?
- Multiple Group By LINQ extension methods
- EF Code First and linq extension methods - foreign keys, am i doing it wrong?
- c# Linq or code to extract groups from a single list of source data
- How do you perform a left outer join using linq extension methods
- How to do joins in LINQ on multiple fields in single join
- Code equivalent to the 'let' keyword in chained LINQ extension method calls
- Linq code to select one item
- how to update the multiple rows at a time using linq to sql?
- LINQ extension methods - Any() vs. Where() vs. Exists()
- How do I update a single item in an ObservableCollection class?
- linq distinct or group by multiple properties
- update multiple elements at once LINQ
- Can you use LINQ types and extension methods in IronPython?
- Nested "from" LINQ query expressed with extension methods
- Using LINQ to find duplicates across multiple properties
- Using LINQ to group by multiple properties and sum
- Order of LINQ extension methods does not affect performance?
- Nice, clean cross join in Linq using only extension methods
- Use LINQ to concatenate multiple rows into single row (CSV property)
- What is the difference between LINQ query expressions and extension methods
- LINQ to SQL: Multiple / Single .dbml per project?
- Why don't the Linq extension methods sit on IEnumerator rather than IEnumerable?
- Linq way to find value in DataTable
- How to check/compare whether four variables are same or different using conditional statement in C# or C++
- Counting specified columns in Group with LINQ
- Select if criteria is met
- Distinct using Linq query
- LINQ: How to join on only a single row with the MAX ID of the join column, and not all rows?
- How to express LEFT JOIN when 2 entities are linked by a navigation properties
- Trying to update a DataRow in C# with LINQ
- DataGridView is not able to populate by LINQ to SQL object
- Reading Byte[] into Database from API
- Select clause null
- How to use properly linq to perform efficiently a conversion from a DataTable to a set of recursive objects?
- Does anyone know of anyone working on a LINQ-to-Memcached provider?
- Linq - Get the Static class constants as List
- converting value types of an object to Dictionary<string, string>
- LINQ to SQL Query for Many-to-Many relationship
- Using Linq to merge all List returned by the method of an object in a List
- How do I write this in Ruby/Python? Or, can you translate my LINQ to Ruby/Python?
- How to work with dataset's datarelation in linq?
- Access properties in anonymous type collection - C#