How to get a List ordered by the List it's filtered by?
Posted
by DaveDev
on Stack Overflow
See other posts from Stack Overflow
or by DaveDev
Published on 2010-04-29T09:09:30Z
Indexed on
2010/04/29
11:57 UTC
Read the original article
Hit count: 146
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.
© Stack Overflow or respective owner