Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Table-Valued Parameter from local List with Join of DbSet #30556

Closed
philippk80 opened this issue Mar 23, 2023 · 3 comments
Closed

Table-Valued Parameter from local List with Join of DbSet #30556

philippk80 opened this issue Mar 23, 2023 · 3 comments

Comments

@philippk80
Copy link

Hello,
I'm curious if it's possible to build something like that with ef core:

Using a table-valued parameter and fill it with data from a local List using a DataTable.
After this join it with DbSet and the table-valued parameter as table for the inner join.

I have done it with a rawsql. Is there a way to map and fill the table-valued parameter type and build this with ef core on the fly? (without using rawsql at all)

best regards

@philippk80 philippk80 changed the title Table-Valued Parameter from RawSql with Join of DbSet Table-Valued Parameter from local List with Join of DbSet Mar 23, 2023
@roji
Copy link
Member

roji commented Mar 23, 2023

Duplicate of #30426

@roji roji marked this as a duplicate of #30426 Mar 23, 2023
@roji
Copy link
Member

roji commented Mar 23, 2023

This is something we're actively working on at the moment - but with JSON rather than with table-valued parameters or DataTables. SQL Server TVPs require a type to be defined ahead of time, which isn't appropriate for a component such as EF Core. In addition, this is a SQL Server-specific feature which doesn't exist in other databases.

In contrast, SQL Server OPENJSON allows us to send an array of (primitive values) as a JSON string, and unpack that as a table in the database, allowing JOINs and other similar techniques. Benchmarks show that TVPs are actually slower than this OPENJSON, and very similar techniques around JSON exist in all other major databases as well.

See specifically #13617 (comment) for using this to translate Contains over an array of primitive values, and for benchmarks.

@yv989c
Copy link

yv989c commented Mar 28, 2023

Hey @philippk80, while you're waiting, you can give QueryableValues a try. It does exactly what you're asking for, and it even supports OPENJSON behind the scenes.

If you want to see an example that relates to your specific use case, check out this. It shows you how to join data from your local list directly into your EF query.

By the way, I'm assuming that you're using SQL Server.

@ajcvickers ajcvickers closed this as not planned Won't fix, can't repro, duplicate, stale Mar 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants