Inheritance question

Posts   
 
    
mikeg22
User
Posts: 411
Joined: 30-Jun-2005
# Posted on: 26-Oct-2006 19:47:38   

If I have a supertype, say "Super" and a derived type, save "Derived" and I do:


Dim collection as new EntityCollection(new SuperFactory())
adapter.FetchEntityCollection(collection)

will collection contain instances of the derived type? By that I mean it contains entities that can be casted directly to "Derived?"

The reason I can't try this out to test it is that I am in the process of modifying our templates to be able to work with inherited entities and can't actually fetch with an inheritance situation yet. cry

bclubb
User
Posts: 934
Joined: 12-Feb-2004
# Posted on: 27-Oct-2006 00:42:20   

Yes. Check the section about polymorphic fetches under fetching an entity.

// C#, .NET 2.0
CustomerEntity customer = new CustomerEntity("CHOPS");
DataAccessAdapter adapter = new DataAccessAdapter();
EntityCollection<OrderEntity> orders = customer.Orders;
adapter.FetchEntityCollection(orders, customer.GetRelationInfoOrders());

If Order is in an inheritance hierarchy, the fetch is polymorphic. This means that if the customer entity, in this case customer "CHOPS", has references to instances of different derived types of Order, every instance in customer.Orders is of the type it represents, which effectively means that not every instance in Orders is of the same type.