如何获取条件为字符串数组的记录
本文关键字:字符串 数组 记录 条件 何获取 获取 | 更新日期: 2023-09-27 18:36:37
在下面的代码中,profile
是一个字符串。我想知道如何在profile
是字符串数组或列表的情况下编写查询。即数组或列表可以有多个元素,如 { '配置文件1', '配置文件2'}
var ccData = (from p in db.ChannelContacts where p.ProfileId == profile select p);
您可以使用高效连接:
var ccData = from p in db.ChannelContacts
join profileID in profiles // your collection
on p.ProfileId equals profileID
select p;
另一个效率较低的选项是Contains
:
var ccData = from p in db.ChannelContacts
where profiles.Contains(p.ProfileId)
select p;
只需询问profile
是否包含该ProfileId
var ccData = (from p in db.ChannelContacts
where profile.Any(prof => prof == p.ProfileId)
select p);