Best way to handle WhereIn
clauses for queries with large number of parameters
#622
-
Hi! I'm currently in the process of re-writing some report generation using SqlKata. I'm first running one query to get the items for which the report specified, however, after this first query is completed I have to continue building up the properties of the report object, so I'm running additional queries based off the result of the first. For example, I might have to fetch all of the notes for all the customers in the report. (We're not using Dapper, just raw ADO.NET code, so something along the lines of QueryMultiple is not possible) The other queries I created use WhereIn given a list of ID's for the items returned from the report and I'm setting the parameters generated by the compiler's NamedBindings with Parameters.AddWithValue. However SQL Server has an upper limit on the number of parameters a query can have. So I'm exploring alternatives to make the secondary queries work. One easy solution would be to simply use the compilation's Another quick solution would be to re-use the first query and join the result of that query on the others, however the queries can take a while to run, and re-running the original just to join additional data is not ideal. Is there an "officially" supported way to safely replace parameters generated by the compiler? I'd assume not. If there is no way, what approach would you suggest one takes in this situation? Thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
Hello, why not using the |
Beta Was this translation helpful? Give feedback.
Hello, why not using the
WhereIn(Query)
overload?this way you don't have the hard limit limitation of SQL Server for the
WhereIn(List<>)