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 w/ INNER JOIN #386

Closed
r2baka opened this issue Feb 13, 2024 · 1 comment
Closed

Many-to-Many w/ INNER JOIN #386

r2baka opened this issue Feb 13, 2024 · 1 comment

Comments

@r2baka
Copy link

r2baka commented Feb 13, 2024

In the examples here
https://learn.microsoft.com/en-us/ef/core/modeling/relationships/many-to-many

Describing a many-to-many between Blog Posts and Tags. Say I want to find all Blog Posts tagged with a particular tag, intuitively I would do this...

Specification
...
Query.Include(tags => tags.Where(tt => tt.TagText == searchTag));

Now, the SQL produced will be something like this:
Select Posts., Tags.
from Posts LEFT JOIN PostsTags on Posts.Id = PostsTags.PostsId...

This will give me a list of ALL Posts, and the tags will be empty.

I want to tell it to send the SQL with an INNER JOIN, rather than a LEFT join. How do I do that?

In this example, Is there a way to say, bring back only the list of Posts tagged with a particular tag?

@r2baka
Copy link
Author

r2baka commented Feb 13, 2024

I think I may have answered my own question already. I do this:

            Query.Where(p => p.Tags.Select(f => f.TagText).Contains(searchTag));

You folks are incredible that you made that work. Thank you for this wonderful library.

@r2baka r2baka closed this as completed Feb 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant