I have a simple Listone that each row has 50 columns . I want to return all 50 columns + 3 custom columns, but I want to make each row of the list as a flat (not nested) object.
Example:
var newList = list.Select(x => new
{ x,
d.CustomColA = x.ColA+10,
d.CustomColB = x.ColB+30,
d.CustomColC = x.ColC+50
});
Result: It works fine , but each line of the result is like a nested object:
var row = newList.FirstOrDefault();
row.x.ColA
row.x.ColB
row.x.ColC
.....
row.CustomColA
row.CustomColB
row.CustomColB
Expected Result:
var row = newList.FirstOrDefault();
row.ColA
row.ColB
row.ColC
.....
row.CustomColA
row.CustomColB
row.CustomColB
I used the type dynamicand wrote the following code, but it did not return the expected result:
var newList = list.Select(x =>
{
dynamic d = x;
d.CustomColA = x.ColA+10;
d.CustomColB = x.ColB+30;
d.CustomColC = x.ColC+50;
return d;
});
Result in the watch panel: 'newList.FirstOrDefault()' threw an exception of type 'Microsoft.CSharp.RuntimeBinder.RuntimeBinderException'
Update:
: , 50 , , , Select! ( , 53 Select!). .
2: , , , . , . .