【问题标题】:int' does not contain a definition for 'contains' and no extension method 'contains' accepting a first argument of type 'int' could be foundint' 不包含对 'contains' 的定义,并且找不到接受第一个类型为 'int' 的参数的扩展方法 'contains'
【发布时间】:2017-03-23 06:54:00
【问题描述】:

我在使用下面的 LINQ 查询时遇到了下面提到的错误,not inSQL to LINQ 的等价物是什么?我试过 where !cl.change_list_id.contains(from clcl in bitDB.component_labels_change_lists select clcl.change_list_id) 这不起作用?

var lookaheadRunChangeListIds = (from lrcl in bitDB.lookahead_run_change_list
                                 join cl in bitDB.change_lists on lrcl.change_list_id equals cl.change_list_id
                                 where lrcl.lookahead_run_id == lookaheadRunId 
                                 //and cl.change_list_id not in (select clcl.change_list_id from component_labels_change_lists as clcl)
                                 where !cl.change_list_id.contains(from clcl in bitDB.component_labels_change_lists select clcl.change_list_id)                                               
                                 select cl.change_list.ToString()).ToList();

错误

错误 4 'int' 不包含 'contains' 的定义,并且找不到接受第一个类型为 'int' 的参数的扩展方法 'contains'(您是否缺少 using 指令或程序集引用?)

【问题讨论】:

    标签: c# entity-framework linq


    【解决方案1】:

    序列包含 id 而不是相反,这就是错误的说明。你应该交换这些:

    !(from clcl in bitDB.component_labels_change_lists 
      select clcl.change_list_id).Contains(cl.change_list_id)
    

    你也可以试试:

    !bitDB.component_labels_change_lists.Any(clcl => clcl.change_list_id == cl.change_list_id)
    

    但是检查生成的查询并选择更快的查询(这可能对这个有帮助:https://stackoverflow.com/a/1412902/3185569

    【讨论】:

    • 你有任何链接或文档我可以阅读以通过 mysefl 解决这些问题
    • 如何查看生成的查询并查看时间?在哪里可以找到?
    • @user3508811 检查更新的答案,您可以将查询写入 Visual Studio 控制台。您可以使用Stopwatch 类检查时间,Google 可以找到几十个示例。
    • 我试过bitDB.log,它抛出一个错误Error 1 'Dashboard.EntityFramework.BitDatabaseEntities' does not contain a definition for 'Log' and no extension method 'Log' accepting a first argument of type 'Dashboard.EntityFramework.BitDatabaseEntities' could be found (are you missing a using directive or an assembly reference?
    猜你喜欢
    • 2015-11-21
    • 1970-01-01
    • 2014-12-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多