Closed TehWardy closed 5 years ago
Hello @TehWardy ,
Thank you for reporting,
We will look at what can be done with this expression.
We will try to provide you an answer next Monday, dynamic is always a little bit more complex to work with ;)
Best Regards,
Jonathan
Hello @TehWardy ,
The v2.9.7 has been released.
Func
, we now convert to the right return type if they are different but only for type objectHowever, we didn't success to fully make work your expression.
We only removed a few Array
call
((IEnumerable<dynamic>)Data)
.SelectMany((dynamic buyer) => ((IEnumerable<dynamic>)buyer.MASTERDATA)
.SelectMany((dynamic supplier) => ((IEnumerable<dynamic>)supplier.VENDORITEMS)
.Select((dynamic item) => new
{
BuyerFCSRef = buyer.HEADER.CC_Code,
BuyerName = buyer.HEADER.CC_DESC,
Buyer = ((IEnumerable<dynamic>)Companies).FirstOrDefault((dynamic company) => company.HasReference(""FCS"", buyer.HEADER.CC_Code)),
SupplierFCSRef = supplier.VEND_CODE,
SupplierName = supplier.VEND_NAME,
Supplier = ((IEnumerable<dynamic>)Companies).FirstOrDefault((dynamic company) => company.HasReference(""FCS"", supplier.VEND_CODE)),
FunderFCSRef = supplier.FACTOR,
ItemRef = item.REFERENCE,
LineItem = item
})
)
).ToArray()
.GroupBy(i => i.ItemRef)
.Select(group => new { Ref = group.Key, Items = group.ToArray() })
.ToArray();
I'm not sure yet why it was not working with ToArray
but let us know if you need this one fixed as well.
Best Regards,
Jonathan
The ToArray() calls are just a side effect of the processing my JSON processor builds out.
Here's the example of my source that generates the code I build for your expression parser ...
{
"$type": "Core.Objects.Query, Core.Objects",
"From": {
"$type": "Core.Objects.Query, Core.Objects",
"From": { "((IEnumerable<dynamic>)Data)": "(dynamic buyer)" },
"Select": {
"$type": "Core.Objects.Query, Core.Objects",
"From": { "((IEnumerable<dynamic>)buyer.MASTERDATA)": "(dynamic supplier)" },
"Select": {
"$type": "Core.Objects.Query, Core.Objects",
"From": { "((IEnumerable<dynamic>)supplier.VENDORITEMS)": "(dynamic item)" },
"Select": {
"BuyerFCSRef" : "buyer.HEADER.CC_Code",
"BuyerName" : "buyer.HEADER.CC_DESC",
"Buyer" : {
"$type": "Core.Objects.Query, Core.Objects",
"From": { "((IEnumerable<dynamic>)Companies)": "(dynamic company)" },
"Where": "company.HasReference(\"FCS\", buyer.HEADER.CC_Code)",
"Select": { "company": "company" },
"SingleResult": true
},
"SupplierFCSRef" : "supplier.VEND_CODE",
"SupplierName" : "supplier.VEND_NAME",
"Supplier" : {
"$type": "Core.Objects.Query, Core.Objects",
"From": { "((IEnumerable<dynamic>)Companies)": "(dynamic company)" },
"Where": "company.HasReference(\"FCS\", supplier.VEND_CODE)",
"Select": { "company": "company" },
"SingleResult": true
},
"FunderFCSRef" : "supplier.FACTOR",
"Funder" : {
"$type": "Core.Objects.Query, Core.Objects",
"From": { "((IEnumerable<dynamic>)Companies)": "(dynamic company)" },
"Where": "company.HasReference(\"FCS\", supplier.FACTOR)",
"Select": { "company": "company" },
"SingleResult": true
},
"ItemRef" : "item.REFERENCE",
"LineItem" : "item"
}
}
}
},
"GroupBy": "i.ItemRef",
"Select": {
"Ref" : "group.Key",
"Buyer" : "group.First().Buyer",
"Supplier" : "group.First().Supplier",
"Funder" : "group.First().Funder",
"Items" : "group.ToArray()"
}
}
... you should be able to descern from that how it translates.
I might be able to figure out how to remove the excess ToArray() calls but I guess my concern is that "like for like" the equivilent LINQ query should work right?
Thanks for the fast turnaround time on this 👍 I'll pull it now and test!
We will try to investigate why the ToArray
fails next week.
Yes, the LINQ
part should now work.
Hmmm ...
... when it comes to dealing with IEnumerable types quite often it's difficult to map things. Separately but possibly related I've noticed that if I add "using Z.Expressions.Eval" at the top of my code I can't use LINQ any more for the same reason ... could this be what this is?
I'm guessing the reason for this is that your expression stack has parts of the API that looks much like the LINQ API.
Hey @JonathanMagnan just touching base ... any luck here ? No pressure just a quick passing "hey"!
Hello @TehWardy ,
Thank you for the friendly reminder.
The v2.9.11 has been released. Our library should be now compatible with the ToArray
in this kind of situation.
It's possible for you to provide an example of the Ambiguous Match, I didn't success to reproduce it on my side.
Best Regards,
Jonathan
Just tested the sample code I gave you above ... that appears to be working now on my end too. I think the latest version has got it.
Hey Jonathon,
I just yesterday updated to the latest version (2.9.6.0) as I knew today I would be working on this particularly troublesome query (it's brutal not being dynamic to be honest) I've extracted this small piece of it to help identify the problem.
It seems that Eval is not agreeing with the same raw C# and I wondered if you'd lend some light on the subject.
I've also uploaded the code to dot net fiddle here ... https://dotnetfiddle.net/MbZJjf
Please note, if you copy paste this code in to a new console app project, then add refs to newtonsoft.json and z.expressions.eval from nuget you should be good to go (I checked this to be sure you could get up and running ASAP :)