Nhibernate and lazy loading, just want 1 row from the collection?

It depends on if you need "just one" or a certain one if you need the other items in the list later in the same session You can use filters to filter the collection. These filters are defined in the mapping file and activated and parameterized when using the session AliasToEntityMap result transformer which lets you filter the collection within a query batch fetching that fetches a certain amount of elements at once.

It's possible to add batch size, but making batch size to small you may end up having many database calls when iterating over them.

You could populate the collection using HQL or a Criteria which would only select 1 address, however then you won't be able to access the other addresses unless you reload the entity. Worst case, you would need the which wasn't implemented in N.

I think Lazy Loading will not help you here. I would take this responsibility to the AddressDataProvider. You will get a collection of addresses based on the customer and other predicates (I think first address doesn't have any business value.

One more thing first can vary. The order in which addresses are returned is arbitrary. ) - The last visited address.

- The closest address to the customer address. - The latest (added) address etc. Address GetLastVisited(Customer c); Address GetClosest(Customer c); Just my 2 cents.

Is there a Common Criteria for these records you want to see?. (For Eg: Something like the current Addresses?. (say Current addressFlag = 1?) If that is the case, then you can use a Where Clause on the collection mapping.

Eg.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions