无法从“System.Collections.Generic.IEnumerable”转换为“System.L
本文关键字:System 转换 int IEnumerable Collections Generic | 更新日期: 2023-09-27 18:37:10
我收到以下错误实例参数:
无法从"System.Collections.Generic.IEnumerable"转换为"System.Linq.IQueryable"
那么问题是变量Assay.assayKey在表中可能为空,所以我不能使用int assayKey而不是int? assayKey。我对此感到困惑,有人可以帮忙吗? 谢谢
Search Entry
{
int id {get;set;}
int? key {get;set;}
int[] selectedKeys {get;set;}
}
Assay
{
int id {get;set;}
int? AssayKey { get; set; }
}
CollObject
{
Ienumerable<int> keys {get;set;}
}
在我的控制器操作方法中,我执行以下操作来检索 id 数组:
SearchEntry.selectedKeys = (from assays in db.assay
where CollObject.Keys.Contains(assay.AssayKey)
select assays.id).toArray();
好吧,我找到了解决方案。 由于Assay Key是一个可为空的int,我只需要做这样的事情
.Contains(assays.AssayKey ??0)
问题是我不能在可为空的整数上使用 .contains,所以我不得不做这样的事情才能让它工作
.Contains(assays.AssayKey ??0)