System.Linq.Dynamic.Core icon indicating copy to clipboard operation
System.Linq.Dynamic.Core copied to clipboard

"Type" keyword in property behaves incorrectly in GroupBy (via ToDistinctList)

Open brad302 opened this issue 2 years ago • 4 comments

I believe I’ve found an issue with the System.Linq.Dynamics.Core library and the GroupBy method.

It may very well be happening elsewhere but I’ll let you work that out.

With this JSON …

[
  {
    "Name": "Mr. Test Smith",
    "Type": "ACCOUNTSPAYABLE",
    "Something": {
      "Field1": "Test1",
      "Field2": "Test2"
    }
  },
  {
    "Name": "Mr. Test Smith",
    "Type": "DISPATCH",
    "Something": {
      "Field1": "Test1",
      "Field2": "Test2"
    }
  },
  {
    "Name": "Different Name",
    "Type": "ACCOUNTSPAYABLE",
    "Something": {
      "Field1": "Test3",
      "Field2": "Test4"
    }
  }
]

… when I execute GroupBy with the following keySelectornew (Type, Something.Field1) … the resulting data misrepresents the Type field values.

I then create an array of key/values with the grouping results and this is what comes out. You can see that property Type simply comes back as a value of 1 and not the values within the fields themselves.

This is the resulting response from my framework.

[
    {
        "Key": {
            "Type": 1,
            "Field1": "Test1"
        },
        "Values": [
            {
                "Name": "Mr. Test Smith",
                "Type": "ACCOUNTSPAYABLE",
                "Something": {
                    "Field1": "Test1",
                    "Field2": "Test2"
                }
            },
            {
                "Name": "Mr. Test Smith",
                "Type": "DISPATCH",
                "Something": {
                    "Field1": "Test1",
                    "Field2": "Test2"
                }
            }
        ]
    },
    {
        "Key": {
            "Type": 1,
            "Field1": "Test3"
        },
        "Values": [
            {
                "Name": "Different Name",
                "Type": "ACCOUNTSPAYABLE",
                "Something": {
                    "Field1": "Test3",
                    "Field2": "Test4"
                }
            }
        ]
    }
]

If I change the property name from “Type” to something else, it works fine.

Keen to get your thoughts on this.

Thanks

Brad

brad302 avatar Feb 12 '23 10:02 brad302

Hello @brad302,

Thanks for the information, however can you please make a complete working dotnet-fiddle example project to demonstrate this issue?

StefH avatar Mar 03 '23 18:03 StefH

@StefH, hopefully this works for you ... https://dotnetfiddle.net/tOuoRd

I just realised the issue itself is buried in the ToDynamicList() method. From there, it's not doing what I expect. The Key that's being derived is skewed from the actual data when (as previously pointed out) the name of the property is Type.

Hopefully you can help.

Thanks

brad302 avatar Mar 06 '23 01:03 brad302

Any updates on this one by chance?

brad302 avatar May 08 '23 11:05 brad302

@brad302 No updates yet. I need to debug this issue.

StefH avatar Aug 09 '23 16:08 StefH