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

Will DistinctBy be supported in Filtered Include? #31554

Closed
smarts opened this issue Aug 25, 2023 · 4 comments
Closed

Will DistinctBy be supported in Filtered Include? #31554

smarts opened this issue Aug 25, 2023 · 4 comments

Comments

@smarts
Copy link

smarts commented Aug 25, 2023

Ask a question

Is it on the roadmap to support more operations in Filtered Includes? I'm specifically wanting to use OrderByDescending (currently supported) + DistinctBy (currently unsupported) to get multiple max values.

Include your code

I'm using comments instead of actual EF Core configuration/attribution
Ex:

public class ParentEntity
{
  public long Id { get; set; }
  // owned entities
  public List<ChildEntityRevision> ChildEntityRevisions { get; set; }
  // I want the ability to do this 👇🏽 in a Filtered Include
  public IEnumerable<ChildEntityRevision> CurrentRevisions
    => ChildEntityRevisions.OrderByDescending(x => x.Version).DistinctBy(x => x.StableKey);
  // if the former is enabled then this 👇🏽 is trivial to also do via filtered include with an extra `Where` and `Take(1)`
  public ChildEntityRevision? GetCurrentRevisionOrDefault(long stableKey)
    => CurrentRevisions.SingleOrDefault(x => x.StableKey == stableKey);
}

public class ChildEntityRevision
{
  public long StableKey { get; set; }
  // increases with each new revision 
  public long Version { get; set; }
}

Include stack traces

N/A

Include verbose output

N/A

Include provider and version information

N/A

@smarts smarts changed the title Will DistinctBy be supported in Will DistinctBy be supported in Filtered Include? Aug 25, 2023
@roji
Copy link
Member

roji commented Aug 27, 2023

DistinctBy isn't currently supported by EF in any context, outside or inside of filtered includes - #27470 tracks that.

Distinct (without By) is supported, but not within filtered Include; I've opened #31562 to track that.

@smarts
Copy link
Author

smarts commented Aug 28, 2023

@roji thanks for creating that, I've went ahead and upvoted it.
Out of curiosity, do you know if there's already an issue for using GroupBy (in my case with a nested OrderByDescending(…).Take(1) or OrderByDescending(…).First()) in a filtered include? I'm not sure if that would be more palatable to implement or not, but that's another way to accomplish what I want.

@roji
Copy link
Member

roji commented Aug 28, 2023

Not as far as I know... That may be a bit much within filtered include...

@smarts
Copy link
Author

smarts commented Aug 28, 2023

Got it. I'll close this issue now and we'll see what happens with the 2 issues you mentioned above. Thanks again!

@smarts smarts closed this as completed Aug 28, 2023
@roji roji closed this as not planned Won't fix, can't repro, duplicate, stale Aug 28, 2023
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

2 participants