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

Many-to-many using a JSON array column #30551

Open
ajcvickers opened this issue Mar 22, 2023 · 3 comments
Open

Many-to-many using a JSON array column #30551

ajcvickers opened this issue Mar 22, 2023 · 3 comments

Comments

@ajcvickers
Copy link
Member

Similar to #23523 for Cosmos.

@AndriySvyryd
Copy link
Member

AndriySvyryd commented Apr 22, 2023

The array could contain the FK values for the related entities, see npgsql/efcore.pg#1868

@roji
Copy link
Member

roji commented Apr 22, 2023

@AndriySvyryd yeah. I closed npgsql/efcore.pg#1868 as a dup of this.

Modeling-wise, I guess that instead of the user defining a join table, they'd define a join column which must be a (queryable) collection. Each side of the navigation would need to do this in order for the navigation to be bi-directional. No skip navigations would be involved.

Here's how this would work query-wise:

DROP TABLE IF EXISTS Blogs;
DROP TABLE IF EXISTS Posts;
CREATE TABLE Blogs (Id INT IDENTITY PRIMARY KEY, PostIds NVARCHAR(MAX));
CREATE TABLE Posts (Id INT IDENTITY PRIMARY KEY, Name NVARCHAR(MAX));
INSERT INTO Posts (Name) VALUES ('Post1'), ('Post2');
INSERT INTO Blogs (PostIds) VALUES ('[1, 2]');

SELECT * FROM Blogs AS b
CROSS APPLY OpenJson(b.PostIds) WITH (PostId int '$') AS pids
INNER JOIN Posts AS p ON p.Id = PostId;

@AndriySvyryd
Copy link
Member

No skip navigations would be involved.

I think it would still have to be implemented using skip navigations, as that's the only way of having an FK on each side, we just need to allow the FKs to be defined on different types and to use collection properties.

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

3 participants