EntityCollection and Polymorphic fetches

Posts   
 
    
Arif
User
Posts: 29
Joined: 01-Dec-2005
# Posted on: 20-Dec-2005 00:45:52   

I have the following inheritance tree:

Object --- ServicingEntity --------- Employer --------- Branch --------- ServiceRep

When I fetch the Object EntityCollection, it actually does a polymorphic fetch:


objectColl = new EntityCollection(new ObjectRootEntityFactory()) ;

How can I get it to simply return objects of type ObjectRootEntity rather than the actual derived types. Reason being, I need to bind this to a control & need access to a property that is on the ObjectRootEntity but not on the derived entities.

Walaa avatar
Walaa
Support Team
Posts: 14983
Joined: 21-Aug-2005
# Posted on: 20-Dec-2005 09:47:53   

objectColl = new EntityCollection(new ObjectRootEntityFactory()) ;

Will return all objects of type ObjectRoot (knowing that a drived object is of the same type of its parent object)

If you want to retreive objects from the collection in the ObjectRoot type form, cast them to the ObjectRootEntity.

(ObjectRootEntity)objectColl.Item[i];
Arif
User
Posts: 29
Joined: 01-Dec-2005
# Posted on: 20-Dec-2005 14:05:24   

I wanted to bind the entire collection to a DataGridView. Which requires I know ahead of time the properties of the collection; in my case a property of ObjectRoot.

How would I be able to do that in this case?

Walaa avatar
Walaa
Support Team
Posts: 14983
Joined: 21-Aug-2005
# Posted on: 20-Dec-2005 14:45:02   

Which requires I know ahead of time the properties of the collection; in my case a property of ObjectRoot

All properties of ObjectRoot (SuperType) will exist in its SubTypes, every object in the collection will hold all the properties of the ObjectRoot.