0

If I query like this:

query.GroupBy(x => x.Field).Select(x => x.Key).ToList();

I'll get [null, "v1", "v2"] which is fine because some entries had null in x.Field.

If, on the other hand, I use the same query inside of another query

query
    .Take(1)
    .Select(x => new 
    { 
        x.Field2, 
        distinctValues = query.GroupBy(x=> x.Field).Select(x => x.Key).ToList()
    })
    .ToList();

I'll get {Field2: "some value", distinctValues: ["v1","v2"]}.

Why is that and what workaround do I have? (Distinct fails to translate too often).

Progman
  • 16,827
  • 6
  • 33
  • 48
jjaskulowski
  • 2,524
  • 3
  • 26
  • 36

0 Answers0