How to write Linq2Db version of TVP Query #4281
-
I've tried all kinds of ways of doing this but just can't get it to work. How do I convert the following SQL into Linq2Db.
From the reading I've done I think I need to use the FromSql function but I can't get it work. The query doesn't have to be based on an 'IN' but could use an INNER JOIN on the TVP if that's simpler. I've tried code like the following but get various errors, such as
Any help would be much appreciated. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
I think I've used the wrong terminology in this discussion. I think I meant a Table Value Constructor. Anyway, while doing some more searching I discovered this comment: #2145 (comment) which has pointed me at the AsQuery method and I think this will do what I require. I think I can use it something like this:
In case you're interested, the reason I want to use this rather than the IN approach is that there is no limit on the number of values that can be supplied, whereas if you use the IN approach it's limited to about 40,000 with SQL Server. |
Beta Was this translation helpful? Give feedback.
If you ahve 40k records to do a join with, I'd recommend you create a temporary table. Bulk loading the data into the table will most likely be faster than creating an insanely long SQL query and forcing the server to parse it. You can do that as such: