Walaa wrote:
Don't use a prefetch Path for the dropdownList collection.
This second collection should be loaded on its own.
And for databinding with the main entity, you should bind the corresponding FK property of the main entity to the dropDownList SelectedValue property.
We already do this, but this results in three queries to the database:
(Simple scenario)
Query 1: Select all users from the database
Query 2: Prefetch selects all Company rows from tblCompany where CompanyID in (x,y,z...)
Query 3: Select all Company rows to populate dropdown list
Query 2 is obviously a subset of Query 3 records, so I was wondering if we could do away with Query 2 by saying "Here, everything is in Query3's collection, don't build up another one".
Obviously the normal method gets more expensive as you have more related tables, effectively doubling the number of rows stored in memory, and unnecessarily requiring use on the IN() statement on the prefetch.
It's mainly a minor issue provided the prefetch collection remains small, but could get sticky if you have 5000 customers from 4000 companies, requiring a prefetch with IN(n1..n4000) and another collection of 4000 companies for the dropdown.
For situations where there are 5000 customers from 10 companies, the current solution is fine.
And yes, I know that this is an unrealistic example, but it's a case of removing redundancy, and I was interested as to whether or not I could do it in a more efficient manner, and if not, why not
Cheers,
Jason