score:36
Accepted answer
if you only need the ids of the items then mark's answer will do the trick nicely. if you need to return the items themselves (and they don't already have a suitable equals
implementation) then you could try something like this:
// assumes that the id property is an int - change the generic type if it's not
var ids = new hashset<int>(list1.select(x => x.id));
var results = list2.where(x => !ids.contains(x.id));
score:23
this will get you the ids that are only in list2:
var ids = list2.select(x => x.id).except(list1.select(x => x.id));
if your objects compare equal when they have the same id then you can simplify it to:
var objects = list2.except(list1);
Source: stackoverflow.com
Related Query
- LINQ Lambda - Find all ID's in one list that don't exist in another list
- LINQ - Find all items in one list that aren't in another list
- Find all objects in one list that have a property that matches a property in another list of objects
- Select all from one List, replace values that exist on another List
- Find all objects with list attribute element that exist in another list
- Using LINQ to Objects to find items in one collection that do not match another
- Using LINQ to find all keys from one collection that are not in another?
- How do I use Linq to find the elements of a list that are not present in another list?
- linq - how do you do a query for items in one query source that are not in another one?
- Linq expression to get all items in a IList where one field is in another List
- Using LINQ I have a list of lists, how do I select all objects that exist in every list?
- Linq select all numbers that are in any interval from another list of intervals
- How do I get a list of integers that exist in one collection, but not in another of a different type using LINQ?
- Speed Up Performance - LINQ to get items in one LIST, that are not in another List
- How to filter linq query based on all of the values of one property from another list
- C# LINQ Find List Inside Another List, Better way to code this than a foreach loop
- How to use LINQ to find all items in list which have the most members in another list?
- Get List of Records that do not exist in another list - Linq
- The fastest way to find dictionary keys that are not exist in another list
- Extracting a list of objects that exist in another list objects using linq
- Get count of all items in a list that have one of the properties in another list
- Using Linq to find only records that have all matching values in list of flags?
- I need all values in one list that "connect" to all values in another list
- Linq to check if all value from another list exist
- Find all items that are not there in another list takes lot of time
- Dynamic linq query that Contains ALL from another list
- Linq query, select everything from one lists property that starts with a string in another list
- linq : find values in list exist in another list or not?
- SQLite and LINQ: find all objects that have a sub list with all ids present in a supplied list of IDs
- How to write SQL translateable linq code that groups by one property and returns distinct list
More Query from same tag
- Linq Query return a Concat of Dates to String?
- Multiple enumeration and use of Any()
- Compare two DataRows excluding some columns
- EntityFramework, getting Object ID while added to table
- Using Linq to query a List<List<string>>
- Improving a MongoDB LINQ expression to avoid for each loop
- NHibernate Linq - how to select WHERE IN
- How to subtract the result of a query with a result of another query in c# linq?
- Using SUM and Group By in LINQ
- How to make updatable DataGridView of joined Entity Framework tables using Linq query
- How to filtering related entities but with no foreign keys
- LINQ to Entities many to many relationship
- Converting LINQ query syntax to Lambda notation manually
- LINQ how to get data using Id’s
- Is there a Linq equivalent to the unix command uniq
- Convert a dictionary<string,string> to xml
- LINQ DeleteOnSubmit without Primary key
- LINQ Determine if a property on an object in a collection exists in a different collection
- Why Standard Extension Method on IEnumerables
- How to convert string into Boolean flags in C# LinQ?
- How use Distinct in linq & linq to NHibernate by some columns
- getting error while trying to get "Grade" for StudentId=1
- EF Core - complex query
- Nhibernate 3 & LINQ
- Create a new anonymous type list to union onto existing anonymous type list
- PLINQ query giving overflow exception
- Counting category items for each date in dataset (C# with linq)
- Function that can take different tables and operate on common columns
- Linq solution for list of object?
- XML LINQ Select to Object - Using TryParse