Any way to get a EntityCollection with Duplicates (with prefetch objects)and use of a Content object

Posts   
 
    
OlafD
User
Posts: 51
Joined: 18-May-2004
# Posted on: 02-Mar-2012 13:39:58   

We use Adapter with the lates Version.

If there any way to get a EntityCollection with Duplicates (with prefetch objects)and use of a Content object (We like to print duplicate labels from a printer pool (DruckPool).)

Our Report System needs EntityCollection because we use:

DataSet ds = GeneralUtils.ProduceEmptyDataSet(prefetchPath, new ElementCreator());
collection.CreateHierarchicalProjection(ds);
PrintReport(reportDefinition, ds)

Code to fill the collection. (but DISTINCT ist used):

IEntity2 entity = GeneralEntityFactory.Create((EntityType)entiyType);
            
EntityField2 field = (EntityField2)entity.PrimaryKeyFields[0];
DynamicRelation relation = new DynamicRelation((EntityType)entiyType, JoinHint.Inner, EntityType.DruckPoolEntity, string.Empty, string.Empty, field == DruckPoolFields.EntityID);
bucket.Relations.Add(relation);
bucket.PredicateExpression.Add(DruckPoolFields.DruckAusgabeID == druckAusgabe.DruckAusgabeID);
IPrefetchPath2 prefetchPath = GetPrefetchPath();

EntityCollection<EntityBase2> entitycollection = new EntityCollection<EntityBase2>(entity.GetEntityFactory());
Context context = new Context();
context.Add(entitycollection);
//entitycollection.DoNotPerformAddIfPresent = false;
DataAdapter.FetchEntityCollection(entitycollection, bucket, -1, null, prefetchPath);

Thank you.

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 02-Mar-2012 20:07:48   

Hi there.

The main reason for 'distinct' in entity fetches is that the system never materializes duplicate rows in duplicate entity objects, so it will always filter out duplicate entities: either on the client or on the database level. As it's more efficient to do this on the database level, we emit DISTINCT to do that. (more efficient as in: data transportation otherwise is required for every row). On the client we use pk field value hashtables, which might be faster in some edge cases over distinct on the server (e.g. with many fields).

Either way, you can't have duplicates on entityCollections. For that TypedViews, TypedLists and DynamicLists are there.

Another possible option: Write your duplicate resulset in a StoredProcedure. Then Project the SP resulset onto an EntityCollection. Then in the collection to be filled by the projection, set **DoNotPerformAddIfPresent **property to false just before you fill it. I never tried this but I think it's worth a try.

David Elizondo | LLBLGen Support Team
OlafD
User
Posts: 51
Joined: 18-May-2004
# Posted on: 05-Mar-2012 07:19:00   

Thank you, David.

It ends up with : - reading the Entity - make a deep clone for every duplicate Entity - manipulate the primary key, ObjectID - add the Entity to a empty collection - convert the collection to a DataSet (GeneralUtils.ProduceEmptyDataSet and collection.CreateHierarchicalProjection) - merge the DataSet with a 'master' Dataset (masterDataSet.Merge(ds)) - Print the 'master' DataSet.

Olaf