gpt4 book ai didi

c# - int ID 属于 List 的 linq 查询

转载 作者:太空狗 更新时间:2023-10-29 18:02:51 24 4
gpt4 key购买 nike

我在使用 linq 查询时遇到问题。我以前也用过类似的方法,但我现在不明白哪里出了问题。

错误

The best overloaded method match for 'System.Collections.Generic.List.Contains(int)' has some invalid arguments
Argument '1': cannot convert from 'int?' to 'int' ; refers to the where clause of rTestResults

代码:

List<int> rMTCPlates = (from rP in mDataContext.Plates
where rP.SOItem.SONumberID == aSONumber
select rP.ID).ToList();

var rTestResults = from rT in mDataContext.TestSamplesViews
where rMTCPlates.Contains(rT.PlateID)
select rT;

知道发生了什么事吗?

感谢任何帮助,
谢谢

最佳答案

您可以使用 null-coalescing operator这里:

var rTestResults = from rT in mDataContext.TestSamplesViews 
where rMTCPlates.Contains(rT.PlateID ?? 0)
select rT;

关于c# - int ID 属于 List<int> 的 linq 查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2098757/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com