简体   繁体   English

如何在实体框架中按字段查找数据?

[英]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.

相关问题 如何在Entity Framework的外键字段中添加数据? - How can I add data in foreign key field in Entity Framework? 如何使用实体框架将byte [0]添加到图像数据字段中 - How can I add byte[0] into image data field using Entity framework 如何使用Entity Framework将当前日期/时间插入datetime数据类型字段? - How can I insert the current date/time into a datetime data type field using Entity Framework? 如何找出导致实体框架错误的行? - How can I find out the line that caused the error in entity framework? 我如何在实体框架中保留 MassTransit state 数据? - How can i persist MassTransit state data in entity framework? 使用XML存储数据,我如何使用Entity Framework? - Using XML to store data, how can I use Entity Framework? 实体框架:如何将分组依据转换为实体框架声明 - Entity Framework : How can i translate group by to entity framework statement 如何使用 Entity Framework Core 从数据图中分离实体? - How can I detach an entity from data graph using Entity Framework Core? .NET-如何将实体框架(数据实体模型)用于WCF项目? - .NET - How can I use Entity Framework (Data Entity Model) to a WCF Project? 如何在Entity Framework中使用介于两者之间的类从另一个实体获取数据 - How can I get data from another entity using class in between in Entity Framework
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM