Refetching Related Collection (Adapter)

Posts   
 
    
jshallard
User
Posts: 62
Joined: 23-Mar-2005
# Posted on: 27-Jun-2007 20:26:26   

I have seen several threads on this, but am still a little confused on the best way to do this.

I have an entity "Product". This has a related collection of "AdditionalImage" entities. I delete an image entity directly using adapter.DeleteEntitiesDirectly. My related "productEntity.ProductAdditionalImages" is now out of sync. What is the best way to get this collection back into sync? See example of method below for deleting additional image.

public static void RemoveAdditionalImage(ProductEntity productEntity, CMSImage cmsImage)
{
     DataAccessAdapter adapter = new DataAccessAdapter();
    
     adapter.DeleteEntitiesDirectly(
            typeof(Llbl.EntityClasses.AdditionalImagesEntity), 
            cmsImage.CMSImageEntity.GetRelationInfoAdditionalImages());
    
     cmsImage.Delete(false);
}

I am using the adapter templates (V2.5).

Thanks for any help.

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 28-Jun-2007 07:06:34   

Are you sure the OutOfSync happens after the _DeleteEntitiesDirectly _happens? Could you test for me with a simple example if that is the case? However at v2.5 you can change _OutOfSync _flag.

David Elizondo | LLBLGen Support Team
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 28-Jun-2007 15:15:15   

Clear it, then re-fetch it. If you want to use a prefetch path (if images have further relations with other entities) use a context as well

Frans Bouma | Lead developer LLBLGen Pro
jshallard
User
Posts: 62
Joined: 23-Mar-2005
# Posted on: 28-Jun-2007 17:29:26   

Thanks simple_smile