-
Notifications
You must be signed in to change notification settings - Fork 227
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
Support many-to-many via array column instead of via a join table #1868
Comments
Try this: from t1 in ctx.Table1
from t2 in ctx.Table2
where t1.T2Ids.Contains(t1.Id)
select t1 |
It produces the following
Also I meant linq with methods sry :) I might have oversimplified the example: To replace the effect of FKs, I simply added the following code with respective fields
|
@Mrmumu you're apparently trying to mix EF Core's many-to-many with array columns in some complicated way - that's not likely to work. EF Core manages many-to-many by having a third join table in the middle, with foreign keys to each side. If you need further help, please post a full, runnable code sample with the complete model and query you're trying to do. |
I will try to prepare an example |
Sorry for the late response check this repo: https://github.com/MrMuMu/ef-postgres-array-join Now the question is how do I generate the following query on linq method syntax:
update: new field on table2 |
This is definitely not something that EF Core can generate at this point. Note dotnet/efcore#23523 which is about providing this for Cosmos (some info also in dotnet/efcore#16920 (comment)); the same work could be done for PostgreSQL as well. Keeping on the backlog. |
@Bouke that sentence simply talks about storing arbitrary data values (numbers, strings) and not for having EF Core automatically manage many-to-many via PG arrays (i.e. store foreign keys in the array). |
@roji I missed your reply (normally this view auto-updates) and have deleted my original comment as re-reading the comment indeed didn't suggest this exact use-case. Thank you for confirming the same. |
With the work on primitive collections in EF Core (dotnet/efcore#30731), this would be a general EF feature - in other databases which don't support arrays, a JSON array could hold the FKs of the related entities. |
Duplicate of dotnet/efcore#30551 |
I am trying to generate the following sql with linq but no success so far:
Table1:
Table2:
Is this possible with LINQ?
The text was updated successfully, but these errors were encountered: