NHibernate version: NHibernate-2.0.1.GA On SQLServer 2005
Hello,
I have a very strange problem here. The situation is as follows:
I have an Customer class and an Address class. A Customer can have 1 or more Addresses.
So in the Customer domain class I have an ISet of Addresses. <set><one-to-many>...</one-to-many></set> In the Address class I have a reference back to te Customer class. <many-to-one/>
I have 2 datagrids:
Datagrid 1: The customers. Datagrid 2: The Addresses of a selected Customer.
This all works fine. But, i would like to narrow down the number of results in both grids. So I would like to use SetMaxResults. This also works fine for my customers. I do this like:
ICriteria criteria = NHibernateSession.CreateCriteria(persistentType); (persistentType = Customer) criteria.SetFirstResult(0); criteria.SetMaxResults(500);
This narrows down the customers to max 500 rows.
Now I come to the problem part:
I would like to do the same for the addresses. When a user clicks on a customer NHibernate automatically goes querying the related addresses. But I would like to see max 500 addresses per customer. I do this like:
ICriteria criteria = NHibernateSession.CreateCriteria(persistentType); criteria.SetFirstResult(0); criteria.SetMaxResults(500); ICriteria addressCriteria = criteria.CreateCriteria("Address", JoinType.None); addressCriteria.SetFirstResult(firstrow); addressCriteria.SetMaxResults(pagesize);
But this doesn't do anything :( I do not want to change the JoinType because this gives me duplicate entries in the Customer datagrid.
Is there anyone out there that can help me with this problem? Is there maybe another solution for setting the max results on a many-to-one select?
I also wanted to add a restriction to the Address via: criteria.Add(...); but this only works when the JoinType != None
Thanks in advance to you all!!!
Marten
|