score:0
myrepository.all.where(r=>mycollection.select(a=>a.id).contains(r.id))
score:0
linq has an .intersect that should get you want you need.
something like this:
var result = myrepository.intersect(mycollection).tolist();
more info: http://msdn.microsoft.com/en-us/library/system.linq.enumerable.intersect.aspx
score:1
var result = (from r in myrepository.all
join r2 in mycollection on r.id equals r2.id
select r).tolist();
score:4
cache the ids of mycollection into a hashset.
than you can retrieve your result with a where clause like this :
var myidsets = new hashset(mycollection.select(c => c.id));
var result = myrepository.all.where(r=> myidsets.contains(r.id)).tolist();
score:9
from a in myrepository.all
join m in mycollection on a.id equals m.id
select a
Source: stackoverflow.com
Related Query
- Compare id's of objects in two lists and get the list of objects that includes objects with ids occurring in both of them
- Using LINQ. How can I compare two simple lists to give another list of objects in the new and not in the old list?
- Compare Elements in two lists and return a separate list of the original list that is different
- Merge two Lists in C# and merge objects with the same id into one list item
- How can I compare two Lists and create another list where the match?
- How do I compare two lists where one list starts with the other, and only return the "overhang" elements?
- Compare two lists - If any objects property in one list have changed or a new object in list been added, return that object
- How to compare two list and get the differences from first list?
- Compare two lists and add the difference to third list
- Compare two lists from two attributes and add differences to the third list C#
- Compare 2 lists of objects and create a new list based off item properties in the first list not being present in the second with ASP.NET
- Compare two lists and update only if the first list if condition match on second list
- Comparing two lists and removing each item that contains an entry from the other list
- Linq query to join 2 lists of objects and get the altered values as list
- Using Linq and C#, trying to get two lists from a list of master items grouped by two inner lists
- C# compare two Lists by one Property and change value of first List
- Using LINQ to get the difference between two list of objects based only on a single object property
- How to compare two lists on a combination of two properties and select a row which has mismatch in the third property?
- Compare two lists and save matching column to a separate list
- Compare two lists that contain a lot of objects
- How to get list that is the distinct select of other lists (LINQ)?
- Compare two lists that contain a lot of objects (2th part)
- Comparing two lists to get objects that appear in both
- How to Zip two Lists of different size to create a new list that is same as the size of the longest amongst the original lists?
- How to get the union of two sets of objects that inherit from a common class
- Compare lists and return objects that doesn't exist
- Compare two list in C# and reject or select the child list based on conditions using LINQ or foreach
- How to compare two lists with multiple objects and set values?
- Linq to NHibernate: how to get a list of child objects without having the lists nested
- Reading an XML file and create a list of objects that match the XML content
More Query from same tag
- Convert Nested For Loops into a LINQ Expression
- How to create an anonymous type within linq query with TypeScript
- Find the max element in array field in the list of objects
- Linq Return Type
- A query body must end with a select clause or a group clause why is here an error?
- Read XML with Xdocument
- How to handle a linq query that returns zero rows and have it return decimal value?
- Ordering a self-referencing hierarchy in LINQ
- Get list of related objects whose type is in array of types
- can't construct LINQ statement
- How to do run LINQ Count on a Cosmos-db query asynchronously on SDK V3
- group by and sum using linq
- Insert element with LINQ
- Get data with db with lambda expression and coalesce
- Linq find min value of each object
- NullReferenceException on trying to enumerate an empty IQueryable
- how to add a child node inside a nother child node
- Does .Net Core 2.1 Support LINQ and Lambda Expressions?
- Automapper throw error when use Project().To<> in many to many relationship
- Calling static generic LINQ extension method in PowerShell
- Group join skip the first 10 items to print on second page or a method to jump to certain index
- Use SelectMany to extract value from list and pass to groups
- Exploding a range of dates with LINQ
- Func parameter in LINQ expression
- Where-clause in LINQ to SQL Sum() function
- Linq query, how to orderby
- LINQ to XML get elements in c#
- Sum and Group by in linq using Datarows
- Linq query preferences
- Linq to entities compare datetime with milliseconds precision