This is the data I read from database into a datatable.
the datatable called table is now reshaped.
For every same/distinct UnitType + UnitZoom + MemberZoom I create a new Unit and read the MemberId`s into the MemberListId – this should happen in the Order given by the number of the MemberOrder. Sample data:
Unit1: A B C –> P1,P2
Unit2: 1 2 3 –> P9,P12,P4
Unit3: H23 B10 T15 –>X4,T5,Z3,Y1
My code for now that does not proper sort:
var groupedCollection = table.AsEnumerable()
.GroupBy(row => new
{
UType = row.Field<string>("UnitType"),
UZoom = row.Field<string>("UnitZoom"),
MZoom = row.Field<string>("MemberZoom"),
MOrder = row.Field<int>("MemberOrder"),
// I DO NOT WANT the MemberOrder to be in the Group Key, but later on I use this Property to order by it...
});
var unitCollection = groupedCollection
.Select(g => new Unit
{
UnitType = g.Key.UType,
UnitZoom = g.Key.UZoom,
MemberZoom = g.Key.MZoom,
MemberIdList = g.Select(r => r.Field<string>("MemberId")).OrderBy(b => g.Key.MOrder).ToList(),
});
List<Unit> units = unitCollection.ToList();
Its ordering by static value for list:
U should use something like this:
OrderBy(b => b.SomeValue)it should look like this: