EntityCollection.FindMatches and indexing

Posts   
 
    
stefcl
User
Posts: 210
Joined: 23-Jun-2007
# Posted on: 13-Mar-2008 17:51:26   

Hello,

I have an EntityCollection<OrderDetailsEntity> bound to a DataGridView for in-memory editing. An OrderDetailEntity is made of the following fields :

-IDProduct (long) -NoColor (short?) -IDSize (long?) -Quantity (decimal)

The end-user can populate the collection automatically by using a variety of tools (for example : importing an another order, reordering a range of sold products...)

The problem is that the entities in the collection must be unique according to their <IDProduct><NoColor><IDSize> values, so every time the user tries to add a new entity, I have to check if such an OrderDetailEntity already exists, if it does, I increase the Quantity, if not, I insert a new OrderDetailEntity in the collection.

I currently use findMatches to do that because it is the easiest way, but it's way too slow when you have to bulk insert 4200 command lines in an existing order (takes 240 seconds on a good computer) 96% of that time is taken by FindMatches (according to DotTrace).

I have to find a way to speed up the checking, I'm thinking about indexing the position of the entities in the collection according to their <IDProduct><NoColor><IDSize> combo in a dictionary, but I'm not sure if it's a good idea or not...

Any suggestions?

Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 14-Mar-2008 09:47:18   

I think using a Hashtable would be the a good option.

stefcl
User
Posts: 210
Joined: 23-Jun-2007
# Posted on: 17-Mar-2008 14:43:47   

Thanks, It worked well. I just had to write a class to be used as the hash key.