【问题标题】:cannot convert from 'System.Collections.Generic.IEnumerable<int>' to 'System.Linq.IQueryable<int?>无法从 'System.Collections.Generic.IEnumerable<int>' 转换为 'System.Linq.IQueryable<int?>
【发布时间】:2012-06-16 02:26:26
【问题描述】:

我收到以下错误 实例参数:

无法从“System.Collections.Generic.IEnumerable”转换为“System.Linq.IQueryable”

问题是变量 Assay.assayKey 在表中可能为空,所以我不能使用 intassayKey 而不是 int?化验键。我被这件事难住了,有人可以帮忙吗?谢谢

      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)

【问题讨论】:

  • 请不要重新输入您的代码。如果您复制/粘贴它,对每个人都更有益。

标签: c# linq


【解决方案1】:

问题是我不能在一个可以为空的 int 上使用 .contains,所以我不得不做这样的事情来让它工作

.Contains(assays.AssayKey ??0) 

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-02-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-04-21
    • 1970-01-01
    相关资源
    最近更新 更多