-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
Unable to fetch parent entity with children that only match a certain criteria #6685
Comments
@atrauzzi - Can you elaborate more what you are trying to fetch? If you know what your SQL should be then please post it. It will help in translating to LINQ. |
...how do I ensure I always get the matched BagOfSkittles, while filtering the Skittles that belong to it by colour. Even when there are no related Skittles that match. So I guess if I had the following data:
Using the psuedo-linq in my original description, my hope would be to always get every A further refinement would be to specify a specific bag of skittles, and to always get the record, even if none of the colours matched. For example: |
This statement is ambiguous, It does not clarify if you want BagOfSkittles which does not have any matching Skittles. If you are trying to get all BagOfSkittles with If you want to have only those BagOfSkittles which have at least 1 Skittle which satisfy condition then If you want all BagOfSkittles but want to load only Skittles in memory which satisfy the condition then it is filtered include which is being tracked by #1833 |
Yeah, definitely the third. The rest seems obvious otherwise. :) |
@smitpatel, it seems that the second scenario is not working when using an array inside the var skittleNames = new string[] { "Lemon", "Orange", "Strawberry" };
context.BagOfSkittles.Where(b => b.Skittles.Any(s => skittleNames.Contains(s.Name))) This will throw an exception since it cannot be translated to SQL
Is there any alternative so this expression could be translated to SQL ? Thanks in advance.
|
This is in EF Core, I'll use the following schema for my examples:
In short, if I want to fetch a specific
BagOfSkittles
(whether bytype
orid
), how do I ensure I always get the matchedBagOfSkittles
, while filtering theSkittles
that belong to it bycolour
. Even when there are no relatedSkittles
that match.I think what I'm after here is a left join, but the syntax to produce such a query isn't apparent to me and I haven't been able to find it in documentation (yet).
Perhaps something like this?
The text was updated successfully, but these errors were encountered: