"Type" keyword in property behaves incorrectly in GroupBy (via ToDistinctList)
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 keySelector … new (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
Hello @brad302,
Thanks for the information, however can you please make a complete working dotnet-fiddle example project to demonstrate this issue?
@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
Any updates on this one by chance?
@brad302 No updates yet. I need to debug this issue.