简体   繁体   中英

How can i find data by field in entity framework?

var searchIds = new List<int>{1,2,3,4,5};
var result = persons.Where(p => p.Locations.Any(l => searchIds.Any(id => l.Id == id)));

Try following:

class Program
{
    static void Main(string[] args)
    {
        List<Person> persons = new List<Person>();
        List<int> searchIds = new List<int> { 1, 2, 3, 4, 5 };
        List<Person> result = persons.Where(p => p.Locations.Any(l => searchIds.Contains(l.Id))).ToList();
    }
}
public class Person
{
    public List<Location> Locations { get; set; }
}
public class Location
{
    public int Id { get; set; }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM