How to get a List ordered by the List it's filtered by?
- by DaveDev
I have a method as follows. It returns a list of MyTypes which appear to be ordered by myType.Id ascending by default.
public List<MyType> GetMyTypes(List<int> ids)
{
return (from myType in db.MyTypes
where ids.Contains(myType.Id)
select new MyType
{
MyValue = myType.MyValue
}).ToList();
}
So if ids contains
302
300
301
the List returned contains items in ascending order.
What do I need to do to return List<MyType> in the order of ids?
Thanks
edit: I've tried orderby ids.IndexOf(myType.Id) but it throws the exception Method 'Int32 IndexOf(Int32)' has no supported translation to SQL.