-
-
Notifications
You must be signed in to change notification settings - Fork 158
There is no good way to filter by the parent with isnull or isnotnull operators #548
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
Comments
Created a pull request to fix the issue: #549. |
why do you want to check for isnull on the id? Why not check it on the referencing foreign key? |
@wisepotato, you mean the 1st option from the description? |
To be completely clear, here is the class I have
I need to load only top-level items: |
Hi @unicrus, thanks for opening up this issue. Filtering by the existence of relationships seems like a very useful instrument and we should support this. I fully agree the workarounds you mentioned are not desired. I'm not sure however about the semantics you're proposing to implement filtering on (non-)existing relationships Some motivations for this choice:
What are your thoughts on this @unicrus? |
The reason is that Entity Framework generates SQL using expression trees. That doesn't throw a NullReference exception even if Parent is null. It's the same even in NHibernate — you can write
with no issues. So the query I think that the query And I agree that it may not be useful to people who do not work with an SQL database. The expression To summarize, I think, the best solution would be to add support of the |
Thanks for elaborating on this. What you're saying makes sense to me: Thanks :) |
Description
There is no good way to filter by the parent with isnull or isnotnull operators.
If I have a class Child referencing the Parent, both use int as a Key, then I cannot use a filter query like this
api/children?filter[parent.id]=isnull:
— it fails to create the equality expression (because you can't compare int and null).
There are 2 bad workarounds for this right now:
api/children?filter[parent]=isnull:
It causes the loading of the whole Parent hierarchy into attributes.
Environment
The text was updated successfully, but these errors were encountered: