C# 使用Lambda表达式和In限制器
使用Lambda表达式和In限制器 我有一个查询,我想根据一个字段的值限制结果,如果它包含在值列表中C# 使用Lambda表达式和In限制器,c#,visual-studio,linq,C#,Visual Studio,Linq,使用Lambda表达式和In限制器 我有一个查询,我想根据一个字段的值限制结果,如果它包含在值列表中 public List<Client> GetClientsByExtractIds(List<Guid> extractIds) { AJGDMSStagingContext context = new AJGDMSStagingContext(STAGING_CONNECTION_STRING); return cont
public List<Client> GetClientsByExtractIds(List<Guid> extractIds)
{
AJGDMSStagingContext context = new AJGDMSStagingContext(STAGING_CONNECTION_STRING);
return context.Clients.ToList();
}
public List GetClientsByExtractIds(List extractIds)
{
AJGDMSStagingContext=新的AJGDMSStagingContext(暂存连接字符串);
返回context.Clients.ToList();
}
所以它需要类似于:Clients.ExtractId.Contains(ExtractIds)
我的一个选择是获取所有客户机,然后在内存中循环遍历所有客户机,但我更喜欢直接从数据库获取 你的数据来自哪里?在限制器中。。。。在(extractId1、extractId2、extractId3)中添加:出于性能目的,我将
extractIds
声明为HashSet
。但这毕竟是微观优化。宾果。我没有意识到,就像所有的事情一样,linq,它只是看起来有点倒退。我运行了探查器,可以看到(@p0)中有“[t0].[ExtractId]”的位置
return context.Clients.Where(c => extractIds.Contains(c.ExtractId)).ToList();