Duplicates in collections

Posts   
 
    
Posts: 28
Joined: 27-Mar-2007
# Posted on: 05-Nov-2007 13:54:46   

Hi, I have a situation where I have link tables where there is a possibility of duplicate links. I would like to include these duplicates in the entity collection. In the snippet of code, Brochures can have mutiple descriptions some of which could be the same. The link table is BrochureLink. Likewise Descriptions can have multiple content_text some of which could also be the same. The link table for these is DescriptionContent. Can I process these duplicate entities as if they were separate? Currently when I loop through the theDescription collection the last entry in the database table is not included in the collection as it has a duplicate DescriptionId.



EntityCollection<DescriptionEntity> theDescriptions = new EntityCollection<DescriptionEntity>(new DescriptionEntityFactory());
RelationPredicateBucket theRPB = new RelationPredicateBucket(new PredicateExpression(BrochureFields.BrochureId == int.Parse(BrochureId)));
theRPB.Relations.Add(DescriptionEntity.Relations.BrochureLinkEntityUsingDescriptionId);
theRPB.Relations.Add(BrochureEntity.Relations.BrochureLinkEntityUsingBrochureId);
using (IDataAccessAdapter da = new DataAccessAdapter())
{
    da.FetchEntityCollection(theDescriptions,theRPB,0,new SortExpression(BrochureLinkFields.SeqNumber | SortOperator.Ascending));
    if (theDescriptions.Count > 0)
    {
         foreach (DescriptionEntity item in theDescriptions)
         {
             Debug.WriteLine("Getting description : (" + item.DescriptionId.ToString() + ")" + item.DescriptionName);
             EntityCollection<ContentTextEntity> theContent = new EntityCollection<ContentTextEntity>(new ContentTextEntityFactory());
             RelationPredicateBucket theRPB2 = new RelationPredicateBucket(new PredicateExpression(DescriptionFields.DescriptionId == item.DescriptionId));
             theRPB2.Relations.Add(ContentTextEntity.Relations.DescriptionContentEntityUsingContentTextId);
             theRPB2.Relations.Add(DescriptionEntity.Relations.DescriptionContentEntityUsingDescriptionId);
             PrefetchPath2 thePath = new PrefetchPath2((int)EntityType.ContentTextEntity);
             thePath.Add(ContentTextEntity.PrefetchPathHeading);
             SortExpression theSorter = new SortExpression(DescriptionContentFields.SeqNumber | SortOperator.Ascending);
             da.FetchEntityCollection(theContent,theRPB2,0,theSorter,thePath);
             if (theContent.Count > 0)
             {
        // Do processing for each content item
             }
          }
     }
}


LLBLGen Pro 2.0 OS: Vista Type : Adapter DB : SQL 2000

Thanks Michael Mason

goose avatar
goose
User
Posts: 392
Joined: 06-Aug-2007
# Posted on: 05-Nov-2007 21:41:37   

I think you'll be better using dynamic or typed list, when you fetch them with the FetchTypedList method you'll find an overload that accepts an allowDuplicates parameter.