我收到以下错误 实例参数:
cannot convert from 'System.Collections.Generic.IEnumerable' to 'System.Linq.IQueryable'
问题是变量 Assay.assayKey 在表中可能为 null,所以我不能用 int AssayKey 而不是 int?分析 key 。我对此感到困惑,有人可以帮忙吗?谢谢
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;}
}
在我的 Controller 操作方法中,我执行以下操作来检索 id 数组:
SearchEntry.selectedKeys = (from assays in db.assay
where CollObject.Keys.Contains(assay.AssayKey)
select assays.id).toArray();
好吧,我找到了解决方案。由于 Assay Key 是一个可以为 null 的 int,所以我只需要做这样的事情
.Contains(assays.AssayKey ??0)
最佳答案
问题是我无法在可为空的 int 上使用 .contains,因此我必须执行类似的操作才能使其正常工作
.Contains(assays.AssayKey ??0)
关于c# - 无法从 'System.Collections.Generic.IEnumerable<int>' 转换为 'System.Linq.IQueryable<int?>,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11024655/