I am using a NServiceBus Saga with a SagaData class that contains a dictionary.
Whenever a Saga’s handle is called I want to check the dictionary for the existence of a certain object.
However, I realized that in this case NHibernate completely loads the dictionary requiring to query each item in this dictionary.
Since my dictionary contains about 2000 items, this is rather slow.
Apparently there are several NHibernate solutions for this problem but I can not get them to work in the NServiceBus setting.
According to http://nhibernate.info/doc/nhibernate-reference/collections.html one can use CreateFilter() to retrieve a subsets of a collection without needing to initialize the whole collection.
To start, I tried retrieving the count as the hibernate reference suggests:
var count = s
.CreateFilter(Data.Documents, “select count(*)”)
Data is my SagaData and Documents is a Dictionary<Guid, Document>.
Document is a user defined class.
In this case, Hibernate throws a HHibernate.QueryException: ‘The collection was unreferenced’.
Can anyone help me there? I use the out-of-the-box NHibernate configuration with no custom mappings etc.