<small id='H47Hh'></small><noframes id='H47Hh'>

      1. <legend id='H47Hh'><style id='H47Hh'><dir id='H47Hh'><q id='H47Hh'></q></dir></style></legend>
      2. <tfoot id='H47Hh'></tfoot>

          <bdo id='H47Hh'></bdo><ul id='H47Hh'></ul>
      3. <i id='H47Hh'><tr id='H47Hh'><dt id='H47Hh'><q id='H47Hh'><span id='H47Hh'><b id='H47Hh'><form id='H47Hh'><ins id='H47Hh'></ins><ul id='H47Hh'></ul><sub id='H47Hh'></sub></form><legend id='H47Hh'></legend><bdo id='H47Hh'><pre id='H47Hh'><center id='H47Hh'></center></pre></bdo></b><th id='H47Hh'></th></span></q></dt></tr></i><div id='H47Hh'><tfoot id='H47Hh'></tfoot><dl id='H47Hh'><fieldset id='H47Hh'></fieldset></dl></div>

        使用 Contains() 时达到 2100 参数限制 (SQL Server)

        Hitting the 2100 parameter limit (SQL Server) when using Contains()(使用 Contains() 时达到 2100 参数限制 (SQL Server))
          <bdo id='IUAeI'></bdo><ul id='IUAeI'></ul>

                  <tbody id='IUAeI'></tbody>

                <tfoot id='IUAeI'></tfoot>

                <small id='IUAeI'></small><noframes id='IUAeI'>

                <i id='IUAeI'><tr id='IUAeI'><dt id='IUAeI'><q id='IUAeI'><span id='IUAeI'><b id='IUAeI'><form id='IUAeI'><ins id='IUAeI'></ins><ul id='IUAeI'></ul><sub id='IUAeI'></sub></form><legend id='IUAeI'></legend><bdo id='IUAeI'><pre id='IUAeI'><center id='IUAeI'></center></pre></bdo></b><th id='IUAeI'></th></span></q></dt></tr></i><div id='IUAeI'><tfoot id='IUAeI'></tfoot><dl id='IUAeI'><fieldset id='IUAeI'></fieldset></dl></div>
                  <legend id='IUAeI'><style id='IUAeI'><dir id='IUAeI'><q id='IUAeI'></q></dir></style></legend>
                • 本文介绍了使用 Contains() 时达到 2100 参数限制 (SQL Server)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  from f in CUSTOMERS
                  where depts.Contains(f.DEPT_ID)
                  select f.NAME
                  

                  depts 是部门 ID 的列表(IEnumerable)

                  depts is a list (IEnumerable<int>) of department ids

                  这个查询工作正常,直到你传递一个大列表(比如大约 3000 个部门 ID)..然后我得到这个错误:

                  This query works fine until you pass a large list (say around 3000 dept ids) .. then I get this error:

                  传入的表格数据流 (TDS) 远程过程调用 (RPC) 协议流不正确.此 RPC 请求中提供的参数过多.最大为 2100.

                  The incoming tabular data stream (TDS) remote procedure call (RPC) protocol stream is incorrect. Too many parameters were provided in this RPC request. The maximum is 2100.

                  我将查询更改为:

                  var dept_ids = string.Join(" ", depts.ToStringArray());
                  from f in CUSTOMERS
                  where dept_ids.IndexOf(Convert.ToString(f.DEPT_id)) != -1
                  select f.NAME
                  

                  使用 IndexOf() 修复了错误但使查询变慢.有没有其他方法可以解决这个问题?非常感谢.

                  using IndexOf() fixed the error but made the query slow. Is there any other way to solve this? thanks so much.

                  推荐答案

                  我的解决方案(Guids 是您想要过滤的 ID 列表):

                  My solution (Guids is a list of ids you would like to filter by):

                  List<MyTestEntity> result = new List<MyTestEntity>();
                  for(int i = 0; i < Math.Ceiling((double)Guids.Count / 2000); i++)
                  {
                      var nextGuids = Guids.Skip(i * 2000).Take(2000);
                      result.AddRange(db.Tests.Where(x => nextGuids.Contains(x.Id)));
                  }
                  this.DataContext = result;
                  

                  这篇关于使用 Contains() 时达到 2100 参数限制 (SQL Server)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Building a comma separated list?(建立一个逗号分隔的列表?)
                  Errors in SQL Server while importing CSV file despite varchar(MAX) being used for each column(尽管每列都使用了 varchar(MAX),但在导入 CSV 文件时 SQL Server 中出现错误)
                  How can I import an Excel file into SQL Server?(如何将 Excel 文件导入 SQL Server?)
                  Export table to file with column headers (column names) using the bcp utility and SQL Server 2008(使用 bcp 实用程序和 SQL Server 2008 将表导出到带有列标题(列名称)的文件)
                  Concat field value to string in SQL Server(将字段值连接到 SQL Server 中的字符串)
                  SQL Server Bulk insert of CSV file with inconsistent quotes(SQL Server 批量插入带有不一致引号的 CSV 文件)
                  <i id='2RcI4'><tr id='2RcI4'><dt id='2RcI4'><q id='2RcI4'><span id='2RcI4'><b id='2RcI4'><form id='2RcI4'><ins id='2RcI4'></ins><ul id='2RcI4'></ul><sub id='2RcI4'></sub></form><legend id='2RcI4'></legend><bdo id='2RcI4'><pre id='2RcI4'><center id='2RcI4'></center></pre></bdo></b><th id='2RcI4'></th></span></q></dt></tr></i><div id='2RcI4'><tfoot id='2RcI4'></tfoot><dl id='2RcI4'><fieldset id='2RcI4'></fieldset></dl></div>

                    <small id='2RcI4'></small><noframes id='2RcI4'>

                            <tbody id='2RcI4'></tbody>
                            <bdo id='2RcI4'></bdo><ul id='2RcI4'></ul>
                            <legend id='2RcI4'><style id='2RcI4'><dir id='2RcI4'><q id='2RcI4'></q></dir></style></legend>
                            <tfoot id='2RcI4'></tfoot>