I have a LINQ query that gets me all results where the code is contained within a list. This works fine, however I need to keep the order as per the list of codes. So when the EnumerableRowCollection is returned, the rows are in the same order as tehy were in the List.
Here's my current code:
if (productcodes != "")
{
string[] pcodes = productcodes.Split('|');
// Get most recently viewed first
Array.Reverse(pcodes);
List<int> prodCodes = new List<int>();
foreach (string pc in pcodes)
{
if (pc != "")
{
prodCodes.Add(Convert.ToInt32(pc));
}
}
results = results.Where(d => d["ProductCode"] != DBNull.Value && (int)d["ID"] > 0 && prodCodes.Contains((int)d["ProductCode"])).Select(d => d);
}
So I need the EnumerableRowCollection results to be ordered the same as they are in List prodCodes rather than it's own random order.
Any ideas?