This is a migrated thread and some comments may be shown as answers.

How to speed up access to lists?

1 Answer 9 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Wolfgang
Top achievements
Rank 1
Wolfgang asked on 13 Nov 2013, 04:32 PM
Hi 

we have the following

objectA is referenced in objectB
objectB has a IList<TypeA>

We want to remove A from B.

Therefore we used:

If(B.IListOfTypeA != null)
    B.IlistOfTypeA.Remove(objectA);

Which seems to be quite simple.

Now we have the following problem: speed.

We have 4500 objects in the list.
If we try to look wether object B has a list ( If(B.IListOfTypeA != null) ) this command needs over a second.

Digging deeper and using the OpenAccess.Profiler in the profiler is shown that :
Navigation ....TypeB(Key=...).IListOfA takes up the complete time (2 selects with e.g. 993 and 653 ms are shown).

Is there any way to speed it up?

Best regards,
Wolfgang


1 Answer, 1 is accepted

Sort by
0
Viktor Zhivkov
Telerik team
answered on 15 Nov 2013, 03:30 PM
Hi Wolfgang,

The two operations that you are seeing are - one select operation to load the IListTypeA and another to update the foreign key. You can avoid the list loading if you change a bit your code:
  1. Set IsManaged to false for IlistOfTypeA navigation property.
  2. Rewrite the removal code the other way around - objectA.ParentB = null or even objectA.ParentBId = null.
Unfortunately these changes will have some side effects:
  • IsManaged = False means that OpenAccess will not synchronise your navigation properties when you set them and you will need to explicitly add the related objects to the OpenAccess context. This will apply globally so pay attention.
  • Setting directly the foreign key Id will in combination with IsManaged = False will lead to incorrect values in both A.IListOfTypeA and B.ParentB properties - they will contains the old referenced object until you call context.SaveChanges();
  • Setting directly B.ParentB property will not update the foreign key property and A.IListOfTypeA property until context.SaveChanges() is called;
Using the described approach allowed me to cut the required time in half, but I cannot guarantee that you will experience the same performance boost.

Please share your results with us if you decide to apply the suggested optimizations.

Regards,
Viktor Zhivkov
Telerik
OpenAccess ORM Q3 2013 simplifies your model operations even further providing you with greater flexibility. Check out the list of new features shipped with our latest release!
Tags
General Discussions
Asked by
Wolfgang
Top achievements
Rank 1
Answers by
Viktor Zhivkov
Telerik team
Share this question
or