鉴于
public abstract class AbstractOrder
{
//some properties...
}
public class AnonymousOrder:AbstractOrder
{
//some properties...
}
public class PartnerOrder:AbstractOrder
{
//some properties...
}
public AbstractOrder FindOrderByConfirmationNumber(string confirmationNumber)
{
ICriteria criteria =
Session.CreateCriteria(typeof(AbstractOrder))
.SetMaxResults(10)
.AddOrder(Order.Desc("PurchasedDate"))
.Add(Restrictions.Eq("ConfirmationNumber", confirmationNumber));
var l = criteria.List<AbstractOrder>();
AbstractOrder ao = l[0] as AbstractOrder;
return ao as AbstractOrder;
}
有人可以解释为什么
PartnerOrder order = repo.FindOrderByConfirmationNumber(confirmationNumber)
返回一个 AnonymousOrder 类型,我如何让它返回一个 PartnerOrder 类型?