I have an array of Ids, in order, using these ids I then issue a linq query, however I want the results of the linq query to come back in the same order that the Ids in the array are in.
Example:
int[] ids = new [] {10, 9, 8, 7};
var query = from row in context.Table where ids.Contains(row.Id) select row;
How could I ensure that the obtained items are in the same order as those in the array?
You can order the rows by the index of their
Idinids:I’m not sure if the LINQ-to-SQL provider supports this; you may need to perform the ordering using LINQ-to-Objects:
or