【发布时间】:2013-08-19 10:26:59
【问题描述】:
所以,我的实体模型中有一个继承层次结构,如下所示:
class Member
{
public virtual Information Information { get; set; }
public long InformationId { get; set; }
//Other Props
}
class Staff : Member
{
}
class Guest : Member
{
}
class Information
{
public string Name { get; set; }
}
class StaffInformation : Information
{
public DateTime BirthDate { get; set; }
}
class GuestInformation : Information
{
public DateTime Expiry { get; set; }
}
鉴于,我很难将会员信息转换为正确的孩子。例如,我想:
TextBoxFor(model => model.Staff.StaffInformation.BirthDate)
但我能做的是:
TextBoxFor(model => (Entities.StaffInformation)(model.Staff.Information).BirthDate)
我可以指定子项的信息类型吗?一些类似以下伪的东西:
class Staff : Member
{
public StaffInformation Information { get; set; }
}
class Guest : Member
{
public GuestInformation Information { get; set; }
}
有什么建议吗?
【问题讨论】:
标签: c# asp.net-mvc-4 inheritance entity-framework-4.1 code-first