score:3
LINQ is a technology to query sources, not to modify them. So you should not use a query and change something in this query. Instead you can filter what you need to modify and then use a loop to actually apply the changes.
IEnumerable<User> usersWithSmallFiles = users
.Where(u => u.Files.Any(f => f.Size <= 10));
foreach (User u in usersWithSmallFiles)
u.Files = u.Files.Where(f => f.Size > 10).ToList();
You also can't use RemoveAll
on IEnumerable<T>
, it's a List<T>
-method. That's why you have used ToList()
in the query. But on this way you create a new list which is not related to your Files
-list, it just contains the same files but the collection is different, so RemoveAll
is pointless.
Source: stackoverflow.com
Related Query
- Best way to remove elements from list field of list objects
- What is the best way to order a list by numeric field and put objects with value of 0 at the bottom?
- Best way to return a list of a particular property from a list with objects
- LINQ query to return distinct field values from list of objects
- Best way to remove multiple items matching a predicate from a .NET Dictionary?
- LINQ select one field from list of DTO objects to array
- Why does adding a list to another list, using add range, remove the elements from the first list?
- How do you remove trailing objects from a list with linq?
- Best way to get an ordered list of groups by value from an unordered list
- Lambda or LinQ expression to remove certain objects from List
- Remove objects with duplicate properties from List
- How to Remove elements from one List based another list's element and condition?
- How to iterate at elements from a sub list and then remove the sub list from the list? With great performance
- Best method to remove items from a list
- What is the best way to sort a List of objects with a start value?
- Most efficient way to remove items from a list without running into a collection modified exception?
- Get those elements from a List of custom class objects whose one property value is parseable to double
- How to remove (via linq) duplicates from a List of objects
- Best LINQ way to create dictionary from list of custom entities
- Efficient way to remove element from a list at specified indices
- Linq: group objects and remove duplicate elements from their child elements
- Remove objects, and child objects from a list in C# where they match an object property in another list
- Is there a way to remove certain elements from a List<T> with LINQ?
- Best Way To Modify A Property Of Elements In A List According To A Grouping
- GroupBy to remove duplicates from IEnumerable list of objects
- LINQ Lamba Select all from table where field contains all elements in list
- In C#, what is the best way to sort a list of objects by a string property and get correct order?
- What is the correct way of retrieving a given business object from a list of business objects using LINQ Where vs. Find?
- LINQ to remove objects from a list of objects based on another list of objects
- How to remove elements of a list where its string contains sub strings from another list
More Query from same tag
- Type arguments cannot be inferred from usage, Can anyone help please?
- How to get a flattened list back to breezejs through webapi2?
- Inverse list without losing references
- MVC Update Details Controller
- How to join sp to table Linq
- Order two different C# lists with LINQ
- Linq to sql error with identitiy increment field
- linqts - group by multiple properties
- get many-to-many from interface
- Nested querying a xml document using LINQ in c#
- C# IQueryable - How to query a list inside another list
- C# Expression Trees - Dynamic Value Lookup
- Can I clone an IQueryable in linq? For UNION purposes?
- Linq way to check if any other element matches expression while skipping itself
- JQuery Autocomplete within MVC doesnt completely function?
- linq group by where count
- Avoiding Redundancies in XML documents
- linq is taking long to order by datediff
- How can I create multiple XML files in C# when a stored procedure that is called returns a large number of rows?
- Include or exclude where clause in Linq to Sql c# function
- Get Group sum not using group.Sum() in linq
- Linq Join by ids and sort by name
- C# How to turn <T> and Expression<Func<T, string>> selector into T.Select( selector)?
- How to parse XML with namespace
- Regarding FirstOrDefault or SingleOrDefault
- Could not find an implementation of the query pattern for source type 'System.Data.Entity.DbSet` 'Where' not found
- Returning values with a Func Delegate
- Returning xml sub elements from attributed elements with LINQ
- Order weird data linq
- Filter and Match Column on a List of Substrings