LINQ Where query with object list

Looks like you want to return all rows from the table that have an ID contained in the list of objects with the same ID. The following will achieve this. I can modify my answer to suit your need. Just let me know if you are looking for something slightly different.

void Main()
{
    
    var listA = new List<A> { new A { Id = 1 }, new A { Id = 4 } };
    
    var results = context.Table
        .Where(t => listA.Select(l => l.Id).Contains(t.Id))
}
    
public class A
{
    public int Id { get; set; }
}

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top