LINQ,EF Core:从一个列表中存在于另一个列表中的记录中提取记录

LINQ, EF Core : pull record from one list where it exist in other list

我正在使用 Entity Framework 核心应用程序开发 .NET 5。

我有两个列表:

  1. 强类型 class 数据列表 creditCallRecords
  2. 仅格式为 List<string>
  3. 的 ID 列表

我只需要从 creditCallRecords 中提取 id 包含在第二 List<string>.

中的那些记录

我尝试使用以下 LINQ 代码,但出现错误:

(from csvRecord in creditCallRecords
 where csvRecord.CardEaseReference.Contains(recordReferencesToProcess)
 select csvRecord);

错误

Cannot convert system.collection.Generic.List to Char

您将 where 子句写错了方向。 尝试

 where recordReferencesToProcess.Contains(csvRecord.CardEaseReference)

因为 recordReferencesToProcessList<string>,它应该包含 csvRecord.CardEaseReference。以其他方式,来自 csvRecord.CardEaseReference 的字符串被转换为 char[],导致错误