【问题标题】:LINQ, EF Core : pull record from one list where it exist in other list [closed]LINQ,EF Core:从另一个列表中存在的一个列表中提取记录[关闭]
【发布时间】:2021-10-12 08:01:21
【问题描述】:

我正在开发一个带有 Entity Framework Core 的 .NET 5 应用程序。

我有两个列表:

  1. 强类型类数据列表creditCallRecords
  2. ID 列表仅采用List<string> 格式

我只需要从creditCallRecords 中提取ID 包含在第二个List<string> 中的那些记录。

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

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

错误

无法将 system.collection.Generic.List 转换为 Char

【问题讨论】:

  • 我想CardEaseReference 是一个字符串。我说的对吗?
  • 请添加更多代码以显示csvRecord.CardEaseReferencerecordReferencesToProcess 的类型
  • 更正它是字符串
  • @Toxic:recordReferencesToProcess 中的内容是字符串列表吗?

标签: c# entity-framework-core .net-5


【解决方案1】:

您以错误的方向编写了where 子句。 试试

 where recordReferencesToProcess.Contains(csvRecord.CardEaseReference)

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-09-13
    • 2021-10-29
    • 2011-10-13
    • 2017-10-21
    • 1970-01-01
    • 2017-04-28
    • 1970-01-01
    • 2018-12-08
    相关资源
    最近更新 更多