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 Query
- linq extension methods, how to update multiple properties of a single item?
- How to update a single item of liist of objects using LINQ in C#
- How to sort list on multiple properties in one line of code in Linq
- How do you perform a left outer join using linq extension methods
- How to do joins in LINQ on multiple fields in single join
- how to update the multiple rows at a time using linq to sql?
- Multiple WHERE Clauses with LINQ extension methods
- How do I update a single item in an ObservableCollection class?
- How to: Use async methods with LINQ custom extension method
- How to use linq `Except` with multiple properties with different class?
- How to update a single column in LINQ without loading the entire row?
- How to do left joins in LINQ on multiple fields in single join
- How to reuse a linq expression for 'Where' when using multiple source tables
- LINQ: How to do JOIN using the linq extension method style on multiple fields?
- How do C# Linq extension methods perform equality comparison?
- How to find specific item with Linq based on multiple conditions?
- Confused about how to implement extension methods in LINQ to Objects
- How can Array use LINQ extension methods since Array does not implent IEnumerable<T> interface
- How can I rewrite Linq Extension Methods as delegates?
- How to flatten a multi level XML into a single level XML using c# code LINQ
- How to write this code using the Linq Extension Method-Syntax?
- How use Reflection to condition multiple properties to check for equality in a LINQ .Where statement, depending on what class is passed?
- C# - How to achieve multiple matching from a single string by using Linq and Regex?
- How to assign multiple LINQ Include() statements to a variable for code re-use?
- How to select multiple class properties in LINQ Expression?
- how to fetch multiple table data in a single linq query and bind it to a autocomplete search model
- 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?
- C# Linq / How to write below code in single query?
- Update only a single item in linq
- How to convert a SQL with multiple left joins to an Entity Framework LINQ statement using Include methods (No Join methods)?
More Query from same tag
- IQueryable and Count
- Get Except of multiple nested dictionaries using LINQ expression
- Linq to SQL with Mono: Can't connect to my sqlite database
- LINQ- comparison & updating values
- Why use .AsEnumerable() rather than casting to IEnumerable<T>?
- Create an XML from a DataTable
- Display Message When No Data Found Using Linq to Sql using C#
- Read from xml file to objectlist using Linq
- Nested where clause
- Creating objects from xml error {"Value cannot be null.\r\nParameter name: element"}
- C# Linq Filter IEnumerable dynamic property and value
- Where Clause in Entity Framework not returning Correct Result
- Linq: GroupBy vs Distinct
- Optimised way for my Linq or Lambda expression
- Selecting Partial Substring in a LINQ
- C# LINQ DatabaseEntitie Query to first Value in Last Element results in Error
- Composite keys and IsRequired(false)
- Write LINQ subquery C#
- Find top level entities in self referencing table
- find duplicate objects within a list of lists (using linq?)
- How do I order a Group by and Order by a result using Linq
- Sum(ABS(col)) in LInq
- Is default(TSource) a real method?
- c# linq MethodCallExpression for Max(DataRow) used for .GroupedBy().Select()
- LINQ Group results and select from another table
- Getting current item from select in Lambda expression?
- Find Items in List<T> based on id
- Is there way to get the max value from YYYYMM combination?
- linq expression in vb.net
- How to get a file name from a list of files using link query