It seems that i’m missing something trivial.
Anyway, here it goes:
var order = new[]{1,3,2};
var foos = new[]{new Foo{Id=1}, new Foo{Id=2}, new Foo{Id=3}};
How to sort foos by order array using Linq?
Desired result:
foos == new[]{new Foo{Id=1}, new Foo{Id=3}, new Foo{Id=2}};
Edit:
Order contains Foo ids. Sorry that i didn’t mention that. Sometimes it’s even harder to ask question properly than to answer it. 🙂
Okay, the question doesn’t seem to be entirely clear to me, so I’ll try to clarify what I think you’re asking:
Correct?
That would be:
You need a
join ... intoto verify that you don’t have any missing or duplicate IDs infoos. It won’t, however, detect if you’ve got missing or duplicate IDs inorder. If you know that everything will be correct (i.e. there will be exactly one entry infoosfor every entry inorderand vice versa) then a simple join is okay:which can be expressed in dot notation as: