Consider the following linq query
var result = from a in from b in filledTable join c in distinctList on b[0].SerialNumber equals c.Field("SERIAL NUMBER") select new { b, c } group a by new { ab[0].SerialNumber } into d select new { Id = d.Select(x => xb[0].Id), SerialNumber = d.Select(x => xb[0].SerialNumber),
filledTable in my linq query there is a List<dynamic> , which is filled with the fact that the values are returned from sproc and distinctList , is a List<DataRow> , which I distinguishes the values coming from DataTable as as follows:
List<DataRow> distinctList = dt.AsEnumerable().Distinct(DataRowComparer.Default).ToList();
My linq request calls the following JSON
[ { "FilledTableList":[ [ { "Id":[ 2 ], "SerialNumber":[ "1073410" ], "ImportTable":[ [ { "SERIAL NUMBER":"1073410", "PRODUCT TYPE":"Product A" }, { "SERIAL NUMBER":"1073411", "PRODUCT TYPE":"Product B" } ] ] }, { "Id":[ -1 ], "SerialNumber":[ "1073411" ], "ImportTable":[ [ { "SERIAL NUMBER":"1073410", "PRODUCT TYPE":"Proeduct A" }, { "SERIAL NUMBER":"1073411", "PRODUCT TYPE":"Product B" } ] ] } ] ] }]
But I would like the following JSON output
[ { "FilledTableList":[ [ { "Id":[ 2 ], "SerialNumber":[ "1073410" ], "ImportTable":[ [ { "SERIAL NUMBER":"1073410", "PRODUCT TYPE":"Product A" } ] ] }, { "Id":[ -1 ], "SerialNumber":[ "1073411" ], "ImporTable":[ [ { "SERIAL NUMBER":"1073411", "PRODUCT TYPE":"Product B" } ] ] } ] ] }]
Thus, the ImportTable node contains information corresponding to the serial number in the FilleTabledList node above. Everything else seems to work as expected using the linq . Can someone tell me where I'm wrong, please
Update:
My filledTable contains two elements:
{ Id = 2, SerialNumber = "1073410"} { Id = -1, SerialNumber = "1073411"}
In the end, I will have more items in the list, but just to find out why more linq queries don't work, I narrowed it down only to points