I am having a problem with the speed of accessing an association property with a large number of records.
I have an XAF app with a parent class called MyParent
.
There are 230 records in MyParent
.
MyParent
has a child class called MyChild
.
There are 49,000 records in MyChild
.
I have an association defined between MyParent
and MyChild
in the standard way:
In MyChild
:
// MyChild (many) and MyParent (one)
[Association("MyChild-MyParent")]
public MyParent MyParent;
And in MyParent
:
[Association("MyChild-MyParent", typeof(MyChild))]
public XPCollection<MyCHild> MyCHildren
{
get { return GetCollection<MyCHild>("MyCHildren"); }
}
There's a specific MyParent
record called MyParent1
.
For MyParent1
, there are 630 MyChild
records.
I have a DetailView for a class called MyUI
.
The user chooses an item in one drop-down in the MyUI
DetailView, and my code has to fill another drop-down with MyChild
objects.
The user chooses MyParent1
in the first drop-down.
I created a property in MyUI
to return the collection of MyChild
objects for the selected value in the first drop-down.
Here is the code for the property:
[NonPersistent]
public XPCollection<MyChild> DisplayedValues
{
get
{
Session theSession;
MyParent theParentValue;
XPCollection<MyCHild> theChildren;
theParentValue = this.DropDownOne;
// get the parent value
if theValue == null)
{
// if none
return null;
// return null
}
theChildren = theParentValue.MyChildren;
// get the child values for the parent
return theChildren;
// return it
}
I marked the DisplayedValues
property as NonPersistent
because it is only needed for the UI of the DetailVIew. I don't think that persisting it will speed up the creation of the collection the first time, and after it's used to fill the drop-down, I don't need it, so I don't want to spend time storing it.
The problem is that it takes 45 seconds to call theParentValue = this.DropDownOne
.
Specs:
- Vista Business
- 8 GB of RAM
- 2.33 GHz E6550 processor
- SQL Server Express 2005
This is too long for users to wait for one of many drop-downs in the DetailView.
I took the time to sketch out the business case because I have two questions:
How can I make the associated values load faster?
Is there another (simple) way to program the drop-downs and DetailView that runs much faster?
Yes, you can say that 630 is too many items to display in a drop-down, but this code is taking so long I suspect that the speed is proportional to the 49,000 and not to the 630. 100 items in the drop-down would not be too many for my app.
I need quite a few of these drop-downs in my app, so it's not appropriate to force the user to enter more complicated filtering criteria for each one. The user needs to pick one value and see the related values.
I would understand if finding a large number of records was slow, but finding a few hundred shouldn't take that long.