The original post question is getting old, but I have met this problem several times lately and have found a solution that might be of help to others. And, as none of the answers above has given an answer with NHibernate code, I also think this is relevant to post.
In our software product, the users make a selection in the user interface. The front end then passes a list of the corresponding ids to the back end for data querying and manipulation.
First, I needed a function to split up the list of elements into paritions of 1000 elements.
Note, this is VB.NET, but the function itself was found elsewhere on StackOverflow in C#:
Public Shared Iterator Function Partition(Of T)(source As IList(Of T), Optional size As Int32 = 1000) As IEnumerable(Of List(Of T))
For i As Integer = 0 To CInt(Math.Ceiling(source.Count / CDbl(size)))
Yield New List(Of T)(source.Skip(size * i).Take(size))
Next
End Function
This function I have used in several ways. One way is a loop over the list partitions to modify a QueryOver to make a Union of all the part results, like this:
Dim allPartitions As IEnumerable(Of List(Of Integer)) = Partition(idList, SplitSize)
Dim foundObjects As IEnumerable(Of MyEntity) = New List(Of MyEntity)
For Each part As List(Of Integer) In allPartitions
foundObjects = foundObjects.Union(
_session.QueryOver(Of MyEntity) _
WhereRestrictionOn(Function(x) x.ID).IsIn(part).Future())
Next
Another way I have used this is to create an Restriction, that can be applied in QueryOvers. The following function creates such a restriction (ICriterion):
Public Shared Function GetRestrictionOnIds(ids As List(Of Integer), propertyName As String) As ICriterion
Dim allParts As IEnumerable(Of List(Of Integer)) = Partition(ids, SplitSize)
Dim restriction As Disjunction = Restrictions.Disjunction()
For Each part As List(Of Integer) In allParts
restriction.Add(Restrictions.In(propertyName, part))
Next
Return Restrictions.Conjunction().Add(restriction)
End Function
I call that function like this:
Dim wellIdRestriction As ICriterion = GetRestrictionOnIds(wellIdsList, "WellId")
Dim bleedOffs As IList(Of BleedOff) = _session.QueryOver(Of BleedOff)() _
.Where(wellIdRestriction) _
.Where(..... more restrictions...) _
.And(...yet more restrictions....) _
.List().GroupBy(...some function...) _
.ToDictionary(.. key-function, value-function...)