[英]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; }
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.