我有一个如下的方法。它返回一个
MyTypes
列表,这个列表似乎默认按照 myType.Id
升序排序。我希望这个列表按照我传递给方法的 ids
参数排序。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();
}
如果ids
包含
302
300
301
返回的列表将按升序排列。
我需要做什么才能按ids
的顺序返回List<MyType>
?
谢谢
编辑:我尝试过orderby ids.IndexOf(myType.Id)
,但它会抛出异常Method 'Int32 IndexOf(Int32)' has no supported translation to SQL.