I am attempting to fetch a subclass entity by a unique key, UserEnity is an abstract base for Member and NonMember. I would expect this code to return an instance of a concrete type down cast to a UserEntity. If I use the concrete class as the prototype it works.
public UserEntity Find(string external_id)
{
IPrefetchPath2 prefetchPath = new PrefetchPath2((int)EntityType.MailboxEntity);
prefetchPath.Add(UserEntity.PrefetchPathMailbox);
//User is abstract base for Member and NonMember
UserEntityFactory uFactory=new UserEntityFactory();
UserEntity u=(UserEntity)uFactory.Create();
u.ExternalId=external_id;
//Search by unique id
IPredicateExpression p = u.ConstructFilterForUCTypeExternalId();
IDataAccessAdapter adapter = base.GetDataAccessAdapter();
bool userFound = adapter.FetchEntityUsingUniqueConstraint(u, p, prefetchPath);
if (userFound)
{
if (u is MemberEntity)
{
this.FillMemeberExtendedData((MemberEntity )u);
u.IsDirty = false;
}
return u;
}
else
{
return null;
}
}