I have a method as follows. It returns a list of MyTypes
which appear to be ordered by myType.Id
ascending by default. I'd like this list to be ordered by the ids
parameter I pass into the method.
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.