1
所以,我有我的实体模型一个继承层次波纹管:指定继承属性类型为特定子
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; }
}
任何建议?
毫无疑问,我确实同意。我正在寻找另一个实体解决方案。如果我找到它,就没有必要将实体转换为vm,反之亦然,对吗? –
对..但是..稍后考虑延期。如果您突然需要从视图中对模型进行验证,该怎么办?现在,您已将'DataAnnotations'直接绑定到您的模型。他们甚至是POCO?或者它们是否生成?你应该提前思考,否则它会回来咬你。 –