Assuming that you have a
List<Product>
. You want to order that products based on another list. So, you can use something like this:
List<int> sortOrder = new List<int>(){4, 5};
var orderedProducts = context.products
.ToList()
.OrderBy(p=>sortOrder.IndexOf(p.ProductID)==-1 ? 2 : sortOrder.IndexOf(p.ProductID))
.ToList();
This should return a list of products sorted this way:
4
5
1
2
3
6
7
8
9
Good luck!