避免在2100参数限制在LINQ to SQL参数、LINQ、SQL、to

2023-09-03 16:49:28 作者:三分坚强°七分痛

在一个项目,我目前的工作,我需要访问2数据库的LINQ以下列方式:

In a project I am currently working on, I need to access 2 databases in LINQ in the following manner:

我得到一个指定的日期范围为DB1之间的所有行程号列表,而这个存储为长值

I get a list of all trip numbers between a specified date range from DB1, and store this as a list of 'long' values

我进行了广泛的查询,有很多的连接在DB2上,而只关注已列入上述名单,他们的行程数行程。

I perform an extensive query with a lot of joins on DB2, but only looking at trips that have their trip number included in the above list.

但问题是,从DB1行程表往往会返回2100项 - 我当然打了2100参数限制的SQL,这会导致我的第二个查询失败。我一直在寻找办法解决这个,如描述的here,但是这基本上改变我的查询LINQ到对象,这会导致很多问题的影响我加入

Problem is, the trip list from DB1 often returns over 2100 items - and I of course hit the 2100 parameter limit in SQL, which causes my second query to fail. I've been looking at ways around this, such as described here, but this has the effect of essentially changing my query to LINQ-to-Objects, which causes a lot of issues with my joins

是否还有其他解决办法,我可以做什么?

Are there any other workarounds I can do?

推荐答案

作为LINQ到SQL可以调用存储的特效,你可以

as LINQ-to-SQL can call stored procs, you could

有一个存储过程,它接受一个数组作为输入,然后把这些值在一个临时表中加入关于 同样采取一个字符串,它的存储过程拆分

或上传所有的值到一个临时表自己并加入该表。

Or upload all the values to a temp table yourself and join on that table.

不过也许你应该重新考虑这个问题:

However maybe you should rethink the problem:

在SQL Server可以被配置为允许对其他数据库(包括Oracle),如果被允许,这可能是一个选择的表查询。 您可以使用一些复制系统保持DB2?更新行程数表