Please try this. I wrote this without testing or even compiling.
public void ReorderElements(IEnumerable<int> elementSks)
var skToElementsToReorder = GetSession().QueryOver<DocumentElement>()
.WhereRestrictionOn(de => de.DocumentElementSk).IsIn(elementSks.ToArray())
.ToDictionary(el => el.DocumentElementSk, el => el);
int index = 0;
foreach(int sk in elementSks)
// Assumes that the key exists - the .IsIn restriction right before helps
skToElementsToReorder[sk].DisplayOrder = index++;
Somehow I think that this can help: http://code.msdn.microsoft.com/101-LINQ-Samples-3fb9811b (as long as you can zip elementSks together with an index. Let me try a simpler version:
public class /* or struct ? */Element
public string name;
public in sk;
public int index;
// I am not fluent in LINQ, but Linq.Zip might help to generate these?
public class SkTuple
// Now you have an `IEnumerable` of each somehow, and you want to do an update at the same time as you do a join ... like this?
This kind of got me thinking that maybe SQL is king after all - perhaps you want to just save this list of ids into a temp table where table id will be the index, and then call a stored procedure which will use a join and an update like this one: