Inverting EntityCollection

Posts   
 
    
arschr
User
Posts: 894
Joined: 14-Dec-2003
# Posted on: 18-Jun-2008 16:21:30   

I'm using the latest 2.5 Adapter.

I fetch a collection of entities (A) and related entity collections of entity B using a prefetch path and a context. I retrieve 1482 As and 29476 Bs from the database and through the context into collections in 2 seconds.

A->BBBB A->B A-> A->BBBBBBBBBB ...

Now I want to get a collection of Bs without refetching from the database. B->A B->A ...

The context offers me a List<IEntityCore> using GetAll(typeof(B));

If I loop through this list adding it to a new EntityCollection<B> it takes 5 minutes.

1) Is there a better way to do this? (I've already tried GetAdjacencyList with worse results) 2) The EntityCollection.AddRange doesn't see to be able to accept the list from the context. 3) Could the context support "better" collections from GetAll like methods?

Edit: If I set the EntityCollection<B> I'm adding to DoNotPerformAddIfPresent to false and don't add the EntityCollection<B> to the context before adding, the looping method performs in less than a second instead of 5 minutes.

Walaa avatar
Walaa
Support Team
Posts: 14994
Joined: 21-Aug-2005
# Posted on: 18-Jun-2008 16:48:42   

I was going to suggest disabling DoNotPerformAddIfPresent too. As it is time consuming in such cases.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39872
Joined: 17-Aug-2003
# Posted on: 18-Jun-2008 20:37:18   

background info: if DoNotPerformAddIfPresent is set to true, for every add, the collection is doing a check if the entity is already in the list. This is a linear search. So this can be very slow with a lot of entities.

Frans Bouma | Lead developer LLBLGen Pro