KastroNYC wrote:
I kept moving by using FetchCollection instead of FetchEntity and that seemed to provide the polymorphic fetch I was looking for. But it doesn't seem to be the best solution since i am sure before hand that I am only going to need one entity, i was hoping for a way to simply instantiate from the base class using the sytax
OrderEntity o = new OrderEntity(100);
Now if order 100 were a special subtype of order, lets say GoldMemberOrder I could simply do
if(o is GoldMemberOrder)
{
GoldMemberOrder gmo = (GoldMemberOrder)o;
}
The above code scenario works fine as long as I use a FetchCollection so i'm going to stick with that unless someone can provide a better solution.
Erm, what you suggest can never work.
OrderEntity o = new OrderEntity(100);
// fetch o, no matter how
if(o is GoldMemberOrderEntity)
{
// do things
}
this code will ALWAYS skip the if statement, as o is already an instance of OrderEntity. So you already created an instance of a given type. That's not changeable into an instance of another type, it will after the instantiation always stay that type.
What you can also try is FetchNewEntity. So to fetch the order with id 100 in the right type, simply do:
OrderEntity o = (OrderEntity)adapter.FetchNewEntity(new OrderEntityFactory(), new RelationPredicateBucket(OrderFields.OrderId == 100));
After THIS code, o can be a different type than OrderEntity, i.e. a subtype of OrderEntity or OrderEntity itself.