You should use the following code:
private EntityCollection< OrderEntity > orderColl;
orderColl = customerEnt.Order;
Taking into consideration that customerEnt.Order will contain entities of type MyOrderEntity, since it uses MyOrderEntityFactory.
If you check the MyCustomerEntity you find the following:
public override EntityCollection<OrderEntity> Order
{
get
{
EntityCollection<OrderEntity> toReturn = base.Order;
toReturn.EntityFactoryToUse = new MyOrderEntityFactory();
return toReturn;
}
}
private EntityCollection ordColl;
ordColl.EntityFactoryToUse = new OrderEntityFactory();
ordColl = customerEnt.Order;
The first two code lines are what is generated when I drag the general EntityCollection onto a form and then set the Entity factory, so that I can use it to set up a grid.
The ordColl is not a Generic collection, while the customerEnt.Order is a generic collection.
the nongeneric EntityCollection type in the helperclasses is really EntityCollection<EntityBase>, and it can't be cast from EntityCollection<SomeEntity>, as that would mean covariance which isn't supported by C# and VB.NET
Is there a way to populate this order collection from customerEnt.Order or is it necessary to create another collection, populate it and set the grid's datasource to the new collection?
Either you directly use the customerEnt.Order, e.g. in databinding you can directly bind the customerEnt.Order to a dataGridView or to a bindingSource.
Or else fetch the ordColl, and don't assign customerEnt.Order.